[HTTPS] REST-love -> Crossplatform Async HTTPS Request

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
Hipreme
Prole
Posts: 15
Joined: Wed Jun 03, 2020 9:57 pm
Contact:

[HTTPS] REST-love -> Crossplatform Async HTTPS Request

Post by Hipreme »

Hello guys, I made a mega wrapper for HTTPS requests, tested on Linux, Windows, Android and Web(Love.js)
Those requests are async (and could be made sync if that is your choice)
The wrapper is REALLY easy to use and there is no adaptation is required between those platform (Except web where you need to include a

Code: Select all

<script src="consolewrapper.js"></script>
And that's all
For using it, just

Code: Select all

require "REST"
function love.load()
    --                URL            REQUEST-HEADER(TABLE FORMAT)     ONLOAD
    REST.get("https://example.com", nil, function(data)print(data);end)
end
function love.update(dt)
    REST.retrieve(dt)
end
Current supported REST methods:
  • GET
  • POST
  • PUT
  • DELETE
  • HEAD
  • PATCH
Together with this lib, comes too a
Module-Loader
You can easily other fully-pledged libraries into your project without adapting anything:

Code: Select all

require "module-loader"
--         LIBPATH        FILE
requireFromLib("js", "js")
requireFromLib("luajit-request", "luajit-request")
If one of those libraries call its own "require", you won't need to adapt anything, the start path for require will be the libpath

In this lib you can still find:
Async(Coroutine)Loader + LoadBar
With that, you can pass your own load function, it will be executed on the coroutine, it is a singleton
LoadBar is a simple bar that you can pass your own backFrame and frontFrame and render it(Doesn't use stencil yet), for using it, is very simple, and if not texture is provided, it uses a default rect for loading(nice for testing):

Code: Select all

require "loadbar"
loadBarInstance = LoadBar:new(width, height, frontTexture, backTexture)
imgs = {}
loadBarInstance.addContentToLoad(function()
    imgs["myImg"] = love.graphics.newImage("myImg.png")
end, nil, "Loading myImg: $")
$ will be replaced by the current load percentage (current[0-100]%) format
Then, you just need to call in love.update

Code: Select all

loadBarInstance:update(dt)
And that's all folks, if you wish to contribute, feel free as AsyncLoader and LoadBar is still wip
REST-love
User avatar
dusoft
Party member
Posts: 502
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: [HTTPS] REST-love -> Crossplatform Async HTTPS Request

Post by dusoft »

This is great, thanks!

I used http socket library in the past project of mine:
http://w3.impa.br/~diego/software/luasocket/http.html

But I will give yours a try. The socket lib is sync only AFAIK.
User avatar
zorg
Party member
Posts: 3441
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: [HTTPS] REST-love -> Crossplatform Async HTTPS Request

Post by zorg »

dusoft wrote: Fri Jul 17, 2020 7:51 am The socket lib is sync only AFAIK.
More importantly, it doesn't support HTTPS, and this seems to, at least .

(Also, unrelated to the quoted message, but the OP's luajit-request fork added a binary of curl into it; depending on what that was built with, license-wise it might not be a great idea, due to restrictions posed by curl's dependencies... then again, i am not a lawyer.)
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Post Reply

Who is online

Users browsing this forum: No registered users and 161 guests