BeamMP-Server
BeamMP-Server copied to clipboard
[Feature Request] Lua API: Http(s) GET, POST, ...
See specification below.
The API must support both HTTPS and plain HTTP. It must support the POST and GET methods at the least, and HEAD would be nice. Each of these methods must support custom headers (as a Lua table), host (example.com) and target (/index.html) as parameters. The POST method must support a body, with the Content-Length
decided automatically, and the Content-Type
as a parameter. The GET and POST methods must return status code and response body, as well as any headers (does not have to be a return value, but it must be possible to send a POST and get headers of the response).
The function names should be prefixed with the general category, so Http*
, e.g. HttpGET
or something.
I'll do all that.
And when making a request, there will also be an optional Parameter for a callback function to make it non blocking on luas side
Thats not a good idea. Fundamentally the Lua is single-threaded, so this should be an event, not a callback.
Why would a callback be blocking?
And what kind of events would you use? Just emit some kind of multiplayer event?
Why would a callback be blocking?
it is in lua since it is single threaded if you execute the task on function call it will wait until it returns, however if you have it as an event it will execute that event when the data is ready on that same thread, or you can have it take a function as an argument and call that function while holding the lua mutex
I meant the second thing you said. The function could have a callback argument:
MP.HttpGet(host, target, headers, callback)
so the function doesn't actually return anything but it invokes the callback once the request is done
Its the same with event or callback, as long as you can make a callback work properly, im okay with it.
Basically, we know how events work, and they have become an idiom that we use, but if you can make a callback work, do that
Wouldn't an event need some kind of identifier so you don't get the wrong response?
Youd have to specify your own event name, yeah, as i said i like callbacks, if you can make them work
So MP.HttpGet could return a random number/string and the event contains that I'd in the args. So Lua can check it the id is correct
everything is on one thread so you can easily expect the responses in order it will basically be a detached callback
Ok. I'll try to make a callback
yeah sounds good
just make sure to never, ever call lua from any other thread than the one of that state
justmedev dropped it, it's up for grabs. Http.CreateConnection already exists, as a starting point.
Otherwise I'll build it for whatever version we do after 3.1.0.