Http - stingray.Http namespace reference - Stingray Lua API Reference

stingray.Http namespace reference

Description

Implements a simple HTTP client.

Note that this simple client does not support advanced features such as SSL. If you need that you should use the plugin system to link to a more advanced HTTP client, such as Curl.

The Http object is a global singleton and all functions operate on this global singleton.

Enumerations

Status of a HTTP operation.

Functions

Parameters

id :

integer

The ID of the operation.

Returns
This function does not return any values.

After you have called close() you can no longer obtain any information about the request.

Parameters

id :

integer

The ID of the operation.

Returns

string?

The error of the HTTP operation.

The ? notation indicates that this type is optional: there may be zero or one instances of it.

If the status is not ERROR, nil is returned.

Parameters

url :

string

The URL of the resource we should GET.

timeout :

number?

The timeout in seconds after which the request will automatically fail (default 10s).

The ? notation indicates that this type is optional: there may be zero or one instances of it.
Returns

integer

An ID identifying this request.

You can use the returned ID to monitor the progress of the operation. The request will automatically close after the specified timeout, but to conserve memory you should close your requests manually when you are done with them.

Parameters

url :

string

The URL of the endpoint we should POST to.

content_type :

string

The content type of the POST request

body :

string

The body of the POST request

timeout :

number?

The timeout in seconds after which the request will automatically fail (default 10s).

The ? notation indicates that this type is optional: there may be zero or one instances of it.
Returns

integer

An ID identifying this request.

You can use the returned ID to monitor the progress of the operation. The request will automatically close after the specified timeout, but to conserve memory you should close your requests manually when you are done with them.

Parameters

id :

integer

The ID of the operation.

Returns

table?

The result of the HTTP operation.

The ? notation indicates that this type is optional: there may be zero or one instances of it.

If the operation has not FINISHED, nil is returned.

The result is returned as a table with the following fields:

  • status_code: The HTTP status code as an integer.
  • reason_phrase: The HTTP reason phrase associated with the status code.
  • headers: A table with the keys and values of the HTTP headers.
  • body: The body of the HTTP data.
Parameters

id :

integer

The ID of the operation.

Returns

stingray.Http.Status

The status of the HTTP operation.