You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The HTTP backend can be swapped out for anything that has the same API as LuaSocket's socket.http. This is done by setting the value of requests.http_socket. Swapping the HTTPS backend can be done by swapping out requests.https_socket.
Tests
Tests are located in the tests directory and are written using busted.
Install busted:
$ luarocks install busted
Run Tests:
$ busted -p _tests tests
Licensing
lua-requests is licensed under the MIT license. See LICENSE.md for details on the MIT license.
The second argument of a request is a table that can be used to make more advanced requests.
Any request can be made with either a second argument or as a table.
> response = requests.post{url = 'http://httpbin.org/post', data = 'random data'}
or
> response = requests.post{'http://httpbin.org/post', data = 'random data'}
It is common for URL's that need to have some sort of query string.
For example, http://httpbin.org/response-headers?key1=val1&key2=val2.
Adding parameters to a URL query is as simple as passing a table into the params field of the second argument.
By reusing the response.auth you can save time by not needing to reauthenticate again.
response.cookies contains cookies that the server requested to be set for authentication.
Cookies
Cookies can be added to any request by setting the cookies field.
> response = requests.get{'http://httpbin.org/get', cookies = 'cookie!'}
JSON Response
JSON response's can be parsed into a Lua table using response.json().
JSON encoding and decoding is done with lua-cjson.
XML response's can be parsed into a Lua table using response.xml().
XML encoding and decoding is done with xml which is based on RapidXML.
xml_body, error = response.xml()
> print(xml_body[1][1][1])
Wake up to WonderWidgets!">> response = requests.get('http://httpbin.org/xml') > xml_body, error = response.xml() > print(xml_body[1][1][1]) Wake up to WonderWidgets!
The returned xml table can be tricky to parse.
I recommend using inspect to help the first time to help see the table structure.
Proxy
A proxy server can be added as an argument to a request.