Library http

HTTP library, allows sending HTTP requests.

Functions

canRequest() Returns whether a request can be made at the moment, taking into account permissions and the rate limit.
cooldownTime() Returns how long (in seconds) until the next request is allowed.
fetch( url, onSuccess, onFailed, headers ) Performs a GET request.
maxRequestsPerSecond() Returns the maximum number of HTTP requests that are allowed per second.
nextRequest() Returns the timestamp at which you can next run a request, relative to time.sysTime().
post( url, params, onSuccess, onFailed, headers ) Performs a form-encoded POST request.
sendRequest( request ) Sends an HTTP request.


Functions

http.canRequest()
Returns whether a request can be made at the moment, taking into account permissions and the rate limit.

Environment:

Shared
http.cooldownTime()
Returns how long (in seconds) until the next request is allowed.

Environment:

Shared
http.fetch( url, onSuccess, onFailed, headers )
Performs a GET request. Requires the SEND_HTTP_REQUESTS permission to be granted when used on the client side.

Environment:

Shared

Parameters:

  • (string) url: The URL to request.
  • (function) onSuccess: Function to run on success. It's passed the response body, a table of header values, and the response code.
  • (function) onFailed: Function to run on failure. It's passed an error message explaining the failure.
  • (table?) headers: An optional table of headers to include in the request (keys and values must be strings).

Return values:

  1. (boolean) True if the request fired, false otherwise.
  2. (string) If the request did not fire, the reason why.
http.maxRequestsPerSecond()
Returns the maximum number of HTTP requests that are allowed per second.

Environment:

Shared
http.nextRequest()
Returns the timestamp at which you can next run a request, relative to time.sysTime().

Environment:

Shared
http.post( url, params, onSuccess, onFailed, headers )
Performs a form-encoded POST request. Requires the SEND_HTTP_REQUESTS permission to be granted when used on the client.

Environment:

Shared

Parameters:

  • (string) url: The URL to request.
  • (table) params: The table of parameters to send as the (form-encoded) body of the POST request.
  • (function) onSuccess: The function to run on success. It's passed the response body, a table of header values, and the response code.
  • (function) onFailed: Function to run on failure. It's passed an error message explaining the failure.
  • (table?) headers: An optional table of headers to include in the request (keys and values must be strings).

Return values:

  1. (boolean) True if the request fired, false otherwise.
  2. (string) If the request did not fire, the reason why.
http.sendRequest( request )
Sends an HTTP request. Unlike fetch() and post(), this allows defining all parameters of a request, including the body and method. Requires the SEND_HTTP_REQUESTS permission to be granted when used on the client.

Environment:

Shared

Parameters:

  • (HTTPRequest) request: The request to send.

Return values:

  1. (boolean) True if the request fired, false otherwise.
  2. (string) If the request did not fire, the reason why.

Valid XHTML 1.0!