Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Lua API: Http(s) GET, POST, ... #55

Open
lionkor opened this issue Nov 6, 2021 · 18 comments
Open

[Feature Request] Lua API: Http(s) GET, POST, ... #55

lionkor opened this issue Nov 6, 2021 · 18 comments
Labels
feature New feature or request

Comments

@lionkor
Copy link
Contributor

lionkor commented Nov 6, 2021

See specification below.

@lionkor lionkor added the feature New feature or request label Nov 6, 2021
@lionkor lionkor changed the title [Feature Request] Change Lua's Http POST+GET to a generic request function [Feature Request] Lua API: Http(s) GET, POST, ... Mar 5, 2022
@lionkor
Copy link
Contributor Author

lionkor commented Mar 6, 2022

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.

@justmedev
Copy link

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

@lionkor
Copy link
Contributor Author

lionkor commented Mar 7, 2022

Thats not a good idea. Fundamentally the Lua is single-threaded, so this should be an event, not a callback.

@justmedev
Copy link

Why would a callback be blocking?

@justmedev
Copy link

And what kind of events would you use? Just emit some kind of multiplayer event?

@Anonymous-275
Copy link
Member

Anonymous-275 commented Mar 7, 2022

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

@justmedev
Copy link

justmedev commented Mar 7, 2022

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

@lionkor
Copy link
Contributor Author

lionkor commented Mar 7, 2022

Its the same with event or callback, as long as you can make a callback work properly, im okay with it.

@lionkor
Copy link
Contributor Author

lionkor commented Mar 7, 2022

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

@justmedev
Copy link

Wouldn't an event need some kind of identifier so you don't get the wrong response?

@lionkor
Copy link
Contributor Author

lionkor commented Mar 7, 2022

Youd have to specify your own event name, yeah, as i said i like callbacks, if you can make them work

@justmedev
Copy link

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

@Anonymous-275
Copy link
Member

everything is on one thread so you can easily expect the responses in order it will basically be a detached callback

@justmedev
Copy link

Ok. I'll try to make a callback

@Anonymous-275
Copy link
Member

yeah sounds good

@lionkor
Copy link
Contributor Author

lionkor commented Mar 7, 2022

just make sure to never, ever call lua from any other thread than the one of that state

@lionkor lionkor added this to the v3.2.0 milestone May 30, 2022
@lionkor
Copy link
Contributor Author

lionkor commented May 30, 2022

justmedev dropped it, it's up for grabs. Http.CreateConnection already exists, as a starting point.

@lionkor
Copy link
Contributor Author

lionkor commented May 30, 2022

Otherwise I'll build it for whatever version we do after 3.1.0.

Dreae added a commit to Dreae/BeamMP-Server that referenced this issue Nov 27, 2023
@lionkor lionkor moved this to In review in Development Dec 10, 2023
lionkor pushed a commit to Dreae/BeamMP-Server that referenced this issue Dec 21, 2023

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
@lionkor lionkor removed this from the v3.3.0 milestone Dec 24, 2023
@lionkor lionkor added this to the v4.0.0 (develop) milestone Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
Status: In review
Development

Successfully merging a pull request may close this issue.

3 participants