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

Add HTTP client function (GET/POST/etc.) #33

Closed
seansbox opened this issue Apr 10, 2019 · 4 comments
Closed

Add HTTP client function (GET/POST/etc.) #33

seansbox opened this issue Apr 10, 2019 · 4 comments
Assignees
Labels
feature request Enhancement or feature request

Comments

@seansbox
Copy link

seansbox commented Apr 10, 2019

Would it be possible to add a function inside of Lua for http GET, POST, etc.? This could be used for:

  • building a CORS proxy (pass through requests)
  • building OpenID Connect / OAuth2 authentication where the server needs to confirm the authentication keys directly with the provider
  • accessing any non-JSON-based APIs (similar to how jnode does it today)

I actually have a need for all 3 of these things. Could be built using a plugin, but it feels like something that would be relatively easy to build in and provide a lot of potential functionality.

@xyproto xyproto added feature request Enhancement or feature request help wanted New contributors are especially welcome labels Apr 10, 2019
@xyproto xyproto self-assigned this Apr 10, 2019
@xyproto xyproto removed the help wanted New contributors are especially welcome label Apr 10, 2019
@xyproto
Copy link
Owner

xyproto commented Apr 10, 2019

With the httpclient branch it is now possible to perform GET requests like this:

HTTPClient():Get("http://www.guimp.com/")

Or by using a variable for the HTTPClient:

hc = HTTPClient()
hc:Get("http://www.guimp.com/")

Or with URL arguments:

HTTPClient():Get("https://jsonplaceholder.typicode.com/comments", {postId=1, id=2})

Or with URL arguments and HTTP headers:

HTTPClient():Get("https://www.whatismybrowser.com/detect/what-http-headers-is-my-browser-sending", {x=42}, {["X-PoweredBy"]="Bits and bytes"}):match('POWEREDBY.*</td>')

Or POST requests like this:

HTTPClient():Post("https://jsonplaceholder.typicode.com/posts", {}, {["Content-type"]="application/json; charset=UTF-8"}, JSON({title="foo", body="bar", userId=1}))

Does this seem like a somewhat viable approach, or is it too verbose?

@seansbox
Copy link
Author

I think this is a good approach. The verbosity is a good balance of flexibility and simplicity. Any reason to have to instantiate an object versus just having an httprequest function? Are there any stateful parameters or other methods? Looks like only autonomous function calls.

@xyproto
Copy link
Owner

xyproto commented Apr 11, 2019

I added GET, POST and DO as shorthand functions, to the httpclient branch,

Unfortunately, the HTTPClient settings like timing and language seems to be possible to set only once, so I'll have to restructure how the object is stored before this will work, before merging.

@xyproto
Copy link
Owner

xyproto commented Apr 11, 2019

Closing this issue as fixed, please re-open this issue if there should be further issues with this.

@xyproto xyproto closed this as completed Apr 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Enhancement or feature request
Projects
None yet
Development

No branches or pull requests

2 participants