httplib (by sorcerykid)
QuickCurl is a simplified Lua API for command-line tools to perform synchonous requests over HTTP or HTTPS. It acts as a layer of abstraction around the LuaCURL module.
An example of a very simple GET request, which only takes two lines of code:
Code: Select all
local httplib = require( "httplib" )
print( httplib.simple_request( "http://httpbin.org/get" ) )
Code: Select all
luarocks install luacurl
https://bitbucket.org/sorcerykid/httplib
Download Archive (.zip)
Download Archive (.tar.gz)
Source Code License:
The MIT License
Usage Instructions
The following methods are available:
httplib.request( method, url, options )
Perform a request for the given URL via the given method (either "GET" or "POST") and with the given table of options:
- headers - an array of HTTP headers for the request in the format of "Header: Value".
- timeout - the connection timeout for the request in seconds
- user_agent - a string identifying the User Agent performing the request
- post_fields - a hash table of form fields to submit with the POST request
Note: Form fields consist of key value pairs, where each key represents the corresponding field name. Values must be a string or coercible to a string. Tabular values are also accepted, in cases where multiple fields have the same name.
httplib.simple_request( url, options )
Equivalent to calling httplib.request( ) via the "GET" method.
httplib.escape( str )
Encodes the given string for passing to the query portion of a URL.
httplib.unescape( str )
Decodes the given string for receiving from the query portion of a URL.
httplib.get_default_headers( new_headers )
Returns an array of HTTP headers pertaining to "Connection: Keep-Alive" and "Accept-Language: en-us" merged with an optional array of additional headers.