This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
NelaMelin's profile picture

[1.6] HTTP 'REST' API

Started by NelaMelin, 01 April 2013 - 11:46 AM
NelaMelin #1
Posted 01 April 2013 - 01:46 PM
Background
The internet is expanding with lots of APIs designed to use HTTP's 'PUT' and 'DELETE' (also 'HEAD' & 'OPTIONS') methods as well as the classic 'GET' and 'POST', along with increasing complexity being pushed into the HTTP response codes.

Suggestion
A flexible base API for Lua libraries to build ontop of:
reqid = http.send(method [string],
        url [string],
        user [string or nil],
        password [string or nil],
        headers [string 'header: value\nheader2: value2\n']
Where the 'headers' may have a blacklist of headers that can't be modified (i.e. user agent, date).

A way to forget about requests that are taking too long, or otherwise now unwanted:
http.abort(reqid)

Single event for 'done', with all the header/status information provided:

local event, reqid, status, headers, sourceText = os.pullEvent()

event      = 'http_ready'
reqid      = (Same ID as above, up to user/library to remember/store details).
status     = '200 Ok'
headers    = 'Content-Type: Text/Plain\nContent-Length: 11\n'
sourceText = (same as before, filestream to read content)

I'm not aware of how complex creating lua tables in Java is, but if it's not too painful the above header strings with newline delimiters could be converted to lua tables (as associative arrays).

Future work
Some APIs require HTTPs… I'm sure that's the start of a good joke :)/>/>
Dlcruz129 #2
Posted 01 April 2013 - 02:04 PM
Cloudy has stated before that he plans to work on HTTP.
Cranium #3
Posted 01 April 2013 - 02:28 PM
Cloudy has stated before that he plans to work on HTTP.
Indeed he has.I can't wait to see what he has in store.