HTTP Library
CLI HTTP library ("HTTP").
The HTTP library that the CLI uses is separate from Stof. It is required that you give the option to add this library when invoking the CLI. Otherwise, the CLI will not add it and you will not have network access while running your Stof document.
An example using this library can be found on the page REST and Restructure.
HTTP.get(url: str, headers?: map, body?: str | blob, timeout?: float | units, response?: obj): (content_type: str, response_headers: map, body: blob)
HTTP GET request.
The URL argument is required, but everything else is optional. You may skip providing arguments that you do not need. For example "HTTP.get(url, timeout)" would be acceptable. However, if you need all arguments, they are required to be in this order.
The request header map must have string keys and string values (if provided).
Timeout defaults to 5 seconds, but you may use Stof time units as needed.
If a response object is provided, Stof will use the formats it has access to and the Content-Type header in the response headers to parse the response body into the provided object.
If adding a request body, it is helpful to use the Standard Library stringify and blobify functions, creating a body in the format of your choice.
The return type is a tuple, giving you easy access to the response content type, headers, and body. You can then use these to parse the body into the document, or further orchestrate additional requests.
HTTP.post(url: str, headers?: map, body?: str | blob, timeout?: float | units, response?: obj): (content_type: str, response_headers: map, body: blob)
HTTP POST request. Identical in implementation to GET, but uses the POST request method.
HTTP.put(url: str, headers?: map, body?: str | blob, timeout?: float | units, response?: obj): (content_type: str, response_headers: map, body: blob)
HTTP PUT request. Identical in implementation to GET, but uses the PUT request method.
HTTP.delete(url: str, headers?: map, body?: str | blob, timeout?: float | units, response?: obj): (content_type: str, response_headers: map, body: blob)
HTTP DELETE request. Identical in implementation to GET, but uses the DELETE request method.
HTTP.patch(url: str, headers?: map, body?: str | blob, timeout?: float | units, response?: obj): (content_type: str, response_headers: map, body: blob)
HTTP PATCH request. Identical in implementation to GET, but uses the PATCH request method.
HTTP.head(url: str, headers?: map, body?: str | blob, timeout?: float | units, response?: obj): (content_type: str, response_headers: map, body: blob)
HTTP HEAD request. Identical in implementation to GET, but uses the HEAD request method.
Last updated
Was this helpful?