nanos world API Reference Unofficial documentation
Static function Shared Fast

HTTP.RequestAsync

Makes an asynchronous HTTP Request.<br/><br/>The request will be made asynchronously and returned safely in the same thread in the callback provided when it's done.<br/><br/><b>Note:</b> If a request is still running when unloading packages, the server will freeze until it's finished, then the package will unload.

Syntax

Lua
HTTP.RequestAsync(uri, endpoint = "", method = HTTPMethod.GET, data = "", content_type = application/json, compress = false, headers = {}, callback = nil)

Parameters

Name Type Default Description
uri string The main URI (the base address)
endpoint optional string "" The endpoint
method optional HTTPMethod HTTPMethod.GET The HTTP Method to be used
data optional string "" Payload
content_type optional string application/json The <a href='https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types'>Content Type</a> to be used
compress optional boolean false Whether or not to compress the content with gzip
headers optional table {} The <a href='https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers'>Headers</a> to be used
callback optional function nil The result
Callback signature function(status, data, headers)

Examples

Makes an asynchronous HTTP Request
HTTP.RequestAsync("127.0.0.1:7777", "/", HTTPMethod.GET, "", "application/json", false, {}, function(status, data, headers),    Console.Log(status) -- 200,    Console.Log(data) -- "{"players_count":0,"server_name":"nanos world server"}",    Console.Log(headers["Content-Type"]) -- "application/json",,    -- TIP: You can parse it if it's a json return as well,    local json_ret = JSON.parse(data),end)