Page 1 of 1

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

Posted: Fri Jul 10, 2020 3:37 pm
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

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

Posted: Fri Jul 17, 2020 7:51 am
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.

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

Posted: Fri Jul 17, 2020 8:18 am
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.)