QuickCurl Library (simplified HTTP requests)

Post Reply
User avatar
sorcerykid
Member
Posts: 1841
Joined: Fri Aug 26, 2016 15:36
GitHub: sorcerykid
In-game: Nemo
Location: Illinois, USA

QuickCurl Library (simplified HTTP requests)

by sorcerykid » Post

QuickCurl Library
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" ) )
Installation of LuaCURL is beyond the scope of this document, but with Luarocks it should be very straightforward:

Code: Select all

luarocks install luacurl
Repository:

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
By default user_agent is "QuickCurl/1.0" and timeout is 10 seconds and default_headers is the result of get_default_headers( ), as described below.

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests