The HTTPClient Plugin provides access to an HTTP Client to perform requests and return responses.
Variable Name | Type | Default Value |
---|---|---|
NWNX_HTTPCLIENT_REQUEST_TIMEOUT | int | 2000 |
The Client commands are functional by simply loading the plugin.
The HTTP Client contains two functions, NWNX_HTTPClient_SendRequest()
and NWNX_HTTPClient_GetRequest()
and broadcasts two events, NWNX_ON_HTTPCLIENT_SUCCESS
and NWNX_ON_HTTPCLIENT_FAILED
.
The builder constructs an NWNX_HTTPClient_Request
struct with the appropriate information then passes that struct into NWNX_HTTPClient_SendRequest()
which will return a unique request identifier. The request is then sent to the host and upon success or failure the respective event is called.
The event data sent is REQUEST_ID
, STATUS
and RESPONSE
. The REQUEST_ID
event data is the integer returned with NWNX_HTTPClient_SendRequest()
. The structure for that request can then be queried via NWNX_HTTPClient_GetRequest()
. The STATUS
event data is the server HTTP status return code, (usually 200 on success) and the RESPONSE
is the body of text the server returned.
Additionally the event data includes Rate Limit information that some servers provide. These are RATELIMIT_LIMIT
which is how many requests you can send in a given time period, RATELIMIT_REMAINING
is how many requests you have left in that time period and RATELIMIT_RESET
is an epoch timestamp when the request limit is reset again. There is also RETRY_AFTER
which some servers provide which is how long in seconds before you can send another request.
Here is an example of posting an issue to a github repository.
Here's an example of insulting a PC when they enter an area
Then set up an event:
Files | |
file | nwnx_httpclient.nss |
Classes | |
struct | NWNX_HTTPClient_Request |
A structure for an HTTP Client Request. More... | |
Functions | |
int | NWNX_HTTPClient_SendRequest (struct NWNX_HTTPClient_Request s) |
Sends an http method to the given host. More... | |
struct NWNX_HTTPClient_Request | NWNX_HTTPClient_GetRequest (int nRequestId) |
Returns an NWNX_HTTP_Client_Request structure. More... | |
int NWNX_HTTPClient_SendRequest | ( | struct NWNX_HTTPClient_Request | s | ) |
Sends an http method to the given host.
s | The structured NWNX_HTTPClient_Request information. |
Definition at line 71 of file nwnx_httpclient.nss.
struct NWNX_HTTPClient_Request NWNX_HTTPClient_GetRequest | ( | int | nRequestId | ) |
Returns an NWNX_HTTP_Client_Request structure.
nRequestId | The request id returned from NWNX_HTTPClient_SendRequest() |
Definition at line 90 of file nwnx_httpclient.nss.
const int NWNX_HTTPCLIENT_REQUEST_METHOD_GET = 0 |
Definition at line 13 of file nwnx_httpclient.nss.
const int NWNX_HTTPCLIENT_REQUEST_METHOD_POST = 1 |
Definition at line 14 of file nwnx_httpclient.nss.
const int NWNX_HTTPCLIENT_REQUEST_METHOD_DELETE = 2 |
Definition at line 15 of file nwnx_httpclient.nss.
const int NWNX_HTTPCLIENT_REQUEST_METHOD_PATCH = 3 |
Definition at line 16 of file nwnx_httpclient.nss.
const int NWNX_HTTPCLIENT_REQUEST_METHOD_PUT = 4 |
Definition at line 17 of file nwnx_httpclient.nss.
const int NWNX_HTTPCLIENT_REQUEST_METHOD_OPTION = 5 |
Definition at line 18 of file nwnx_httpclient.nss.
const int NWNX_HTTPCLIENT_REQUEST_METHOD_HEAD = 6 |
Definition at line 19 of file nwnx_httpclient.nss.
const int NWNX_HTTPCLIENT_CONTENT_TYPE_HTML = 0 |
Definition at line 26 of file nwnx_httpclient.nss.
const int NWNX_HTTPCLIENT_CONTENT_TYPE_PLAINTEXT = 1 |
Definition at line 27 of file nwnx_httpclient.nss.
const int NWNX_HTTPCLIENT_CONTENT_TYPE_JSON = 2 |
Definition at line 28 of file nwnx_httpclient.nss.
const int NWNX_HTTPCLIENT_CONTENT_TYPE_FORM_URLENCODED = 3 |
Definition at line 29 of file nwnx_httpclient.nss.
const int NWNX_HTTPCLIENT_CONTENT_TYPE_XML = 4 |
Definition at line 30 of file nwnx_httpclient.nss.
const int NWNX_HTTPCLIENT_AUTH_TYPE_NONE = 0 |
Definition at line 37 of file nwnx_httpclient.nss.
const int NWNX_HTTPCLIENT_AUTH_TYPE_BASIC = 1 |
Definition at line 38 of file nwnx_httpclient.nss.
const int NWNX_HTTPCLIENT_AUTH_TYPE_DIGEST = 2 |
Definition at line 39 of file nwnx_httpclient.nss.
const int NWNX_HTTPCLIENT_AUTH_TYPE_BEARER_TOKEN = 3 |
Definition at line 40 of file nwnx_httpclient.nss.