http.client
The HTTP client library, asynchronous requests over the engine http client (garrysmod, chttp or reqwest) with timeouts, cookies, redirects and caching.
Classes & types
Functions
http.client.delete | Sends a DELETE request. |
http.client.get | Sends a GET request. |
http.client.head | Sends a HEAD request. |
http.client.options | Sends an OPTIONS request. |
http.client.patch | Sends a PATCH request. |
http.client.post | Sends a POST request. |
http.client.put | Sends a PUT request. |
http.client.request | Executes an asynchronous http request with the given options. |
#http.client.delete
async function http.client.delete(url: http.RequestURL, headers?: http.RequestHeaders, timeout?: integer): http.Response
Sends a DELETE request.
Parameters
| Name | Type | Description |
|---|---|---|
url | http.RequestURL | The URL to send the request to. |
headersoptional | http.RequestHeaders | The headers to send with the request. |
timeoutoptional | integer | The timeout in seconds. |
Returns
| Type | Name | Description |
|---|---|---|
http.Response | response | The response from the request. |
#http.client.get
async function http.client.get(url: http.RequestURL, headers?: http.RequestHeaders, timeout?: integer): http.Response
Sends a GET request.
Parameters
| Name | Type | Description |
|---|---|---|
url | http.RequestURL | The URL to send the request to. |
headersoptional | http.RequestHeaders | The headers to send with the request. |
timeoutoptional | integer | The timeout in seconds. |
Returns
| Type | Name | Description |
|---|---|---|
http.Response | response | The response from the request. |
#http.client.head
async function http.client.head(url: http.RequestURL, headers?: http.RequestHeaders, timeout?: integer): http.Response
Sends a HEAD request.
Parameters
| Name | Type | Description |
|---|---|---|
url | http.RequestURL | The URL to send the request to. |
headersoptional | http.RequestHeaders | The headers to send with the request. |
timeoutoptional | integer | The timeout in seconds. |
Returns
| Type | Name | Description |
|---|---|---|
http.Response | response | The response from the request. |
#http.client.options
async function http.client.options(url: http.RequestURL, headers?: http.RequestHeaders, timeout?: integer): http.Response
Sends an OPTIONS request.
Parameters
| Name | Type | Description |
|---|---|---|
url | http.RequestURL | The URL to send the request to. |
headersoptional | http.RequestHeaders | The headers to send with the request. |
timeoutoptional | integer | The timeout in seconds. |
Returns
| Type | Name | Description |
|---|---|---|
http.Response | response | The response from the request. |
#http.client.patch
async function http.client.patch(url: http.RequestURL, parameters?: http.Parameters, headers?: http.RequestHeaders, timeout?: integer): http.Response
Sends a PATCH request.
Parameters
| Name | Type | Description |
|---|---|---|
url | http.RequestURL | The URL to send the request to. |
parametersoptional | http.Parameters | The body to send with the request. |
headersoptional | http.RequestHeaders | The headers to send with the request. |
timeoutoptional | integer | The timeout in seconds. |
Returns
| Type | Name | Description |
|---|---|---|
http.Response | response | The response from the request. |
#http.client.post
async function http.client.post(url: http.RequestURL, parameters?: http.Parameters, headers?: http.RequestHeaders, timeout?: integer): http.Response
Sends a POST request.
Parameters
| Name | Type | Description |
|---|---|---|
url | http.RequestURL | The URL to send the request to. |
parametersoptional | http.Parameters | The body to send with the request. |
headersoptional | http.RequestHeaders | The headers to send with the request. |
timeoutoptional | integer | The timeout in seconds. |
Returns
| Type | Name | Description |
|---|---|---|
http.Response | response | The response from the request. |
#http.client.put
async function http.client.put(url: http.RequestURL, parameters?: http.Parameters, headers?: http.RequestHeaders, timeout?: integer): http.Response
Sends a PUT request.
Parameters
| Name | Type | Description |
|---|---|---|
url | http.RequestURL | The URL to send the request to. |
parametersoptional | http.Parameters | The body to send with the request. |
headersoptional | http.RequestHeaders | The headers to send with the request. |
timeoutoptional | integer | The timeout in seconds. |
Returns
| Type | Name | Description |
|---|---|---|
http.Response | response | The response from the request. |
#http.client.request
async function http.client.request(options: http.Request): http.Response
Executes an asynchronous http request with the given options.
Response header names are always lowercase.
Responses of cache requests are copies, so they can be changed freely.
With cookies and the chttp client, redirects are followed in Lua (up to max_redirects), so the cookies set by every redirect response are stored.
Parameters
| Name | Type | Description |
|---|---|---|
options | http.Request | The request options. |
Returns
| Type | Name | Description |
|---|---|---|
http.Response | data | The response. |
See also
http.Requestfor the request options structure.http.Responsefor the response structure.