HTTPLite
Simple HTTP/HTTPS requests, with some JSON as a bonus.
mkxp-z includes minimal support for communicating with HTTP servers. Support for unencrypted HTTP is always present; HTTPS requires building with the use_https=true
option, and OpenSSL installed onto the system.
JSON and HTTP support are built on top of json5pp and cpp-httplib respectively. All functions can raise MKXPError
if something goes wrong.
JSON
HTTPLite::JSON.stringify(obj)
takes one object as an argument, transforming it into a JSON string. AcceptsNil
,Float
,Integer
,String
,Array
, andHash
.HTTPLite::JSON.parse(str)
takes one JSON string as an argument, transforming it back into its Ruby equivalent.
HTTP
The HTTP methods all return a hash as a response. This hash contains 3 members (at the moment):
:status (Int)
contains the response status (e.g. 200, 404):body (String)
contains the body portion of the server's response.:headers (String => String)
contains a hash with all the headers contained in the server's response.
The HTTPLite module contains three functions. All return a hash formed in the way described above. They can all be optionally passed headers, as a hash with String
values and String
keys.
By default, these functions will attempt to follow redirect responses. This can be disabled by passing false
to follow_redirects
.
HTTPLite.get(url[, headers[, follow_redirects]])
takes a url as a string, performing a GET request.HTTPLite.post(url, stringhash[, headers[, follow_redirects]])
takes a url as a string, and post data contained as a hash of string keys and string values, performing a POST request.HTTPLite.post_body(url, bodycontent, contenttype[, headers[, follow_redirects]])
takes a url as a string, the request's body as a string, and the body's MIME-type as a string, performing a POST request.
Last updated