From The Powder Toy
Revision as of 19:56, 16 January 2020 by LBPHacker (talk | contribs) (Add HTTP API page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The HTTP API provides access to basic HTTP functionality. Depending on how TPT is built, it may only work with secure sites (ones that use TLS, i.e. HTTPS) or it may not even be available.

assert(http, "HTTP functionality unavailable")




string HTTPRequest:status()

Returns one of the following:

  • "running" if the request hasn't finished yet;
  • "done" if the request has finished and the response body is ready to be read;
  • "dead" if the request is dead, i.e. if it has been cancelled or if the response body has been read.


number, number HTTPRequest:progress()

If the request is not dead, returns the size of the response body in bytes in the first return value (-1 if the size is not known), and the number of bytes received so far in the second. If the request is dead, returns nothing.


nil HTTPRequest:cancel()

Cancels the request. Does nothing if the request is dead.


string, number HTTPRequest:finish()

Finishes the request and returns the response body and the status code. Call this only when HTTPRequest:status returns "done". Does and returns nothing if the request is dead.



HTTPRequest http.request(string uri, [table post_params, [table headers]])

Constructs a HTTPRequest object and starts the underlying request immediately with the URI, post parameters and headers supplied. Both optional tables are collections of string key and string value pairs.