Ir para o conteúdo principal
Version: latest - a1.172.0 ⚖️

🌐 HTTP

HTTP Requests Interface

🗿Static ClassClient & Server🧑‍💻API Source

🎒 Examples​

(HTTP.Request) Makes a synchronous HTTP Request
local ret = HTTP.Request("127.0.0.1:7777", "/", HTTPMethod.GET, "", "application/json", false, {})

Console.Log(ret.Status) -- 200
Console.Log(ret.Data) -- "{"players_count":0,"server_name":"nanos world server"}"
Console.Log(ret.Headers["Content-Type"]) -- "application/json"
(HTTP.RequestAsync) 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)
tip

All requests are thread safe! 🥳 This means that callbacks are returned on the main thread!

🗿 Static Functions​

Request: tableMakes a synchronous HTTP Request
RequestAsyncMakes an asynchronous HTTP Request
SetConnectionTimeoutSets the HTTP requests global Connection Timeout in seconds
SetReadWriteTimeoutSets the HTTP requests global Read and Write Timeout in seconds

RequestBlocking​

Makes a synchronous HTTP Request

The request will be made synchronously and will freeze the server until it's done

local ret = HTTP.Request(uri, endpoint?, method?, data?, content_type?, compress?, headers?)
Parameters
NameTypeDescrição
uristringThe main URI (the base address)
endpoint?stringThe endpoint Default
method?HTTPMethodThe HTTP Method to be used Default HTTPMethod.GET
data?stringPayload Default
content_type?stringThe Content Type to be used Default application/json
compress?booleanWhether or not to compress the content with gzip Default false
headers?tableThe Headers to be used Default {}
Returns
TypeDescrição
tableTable with the response <code>Status</code>, <code>Data</code> and <code>Headers</code>
Table keys
NameTypeDescrição
StatusintegerNo description provided
DatastringNo description provided
HeaderstableNo description provided
Examples (1)
Makes a synchronous HTTP Request
local ret = HTTP.Request("127.0.0.1:7777", "/", HTTPMethod.GET, "", "application/json", false, {})

Console.Log(ret.Status) -- 200
Console.Log(ret.Data) -- "{"players_count":0,"server_name":"nanos world server"}"
Console.Log(ret.Headers["Content-Type"]) -- "application/json"

RequestAsyncOptimal​

Makes an asynchronous HTTP Request

The request will be made asynchronously and returned safely in the same thread in the callback provided when it's done.

Note: If a request is still running when unloading packages, the server will freeze until it's finished, then the package will unload

HTTP.RequestAsync(uri, endpoint?, method?, data?, content_type?, compress?, headers?, callback?)
Parameters
NameTypeDescrição
uristringThe main URI (the base address)
endpoint?stringThe endpoint Default
method?HTTPMethodThe HTTP Method to be used Default HTTPMethod.GET
data?stringPayload Default
content_type?stringThe Content Type to be used Default application/json
compress?booleanWhether or not to compress the content with gzip Default false
headers?tableThe Headers to be used Default {}
callback?functionThe result with this format Default nil
Examples (1)
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)

SetConnectionTimeoutOptimal​

Sets the HTTP requests global Connection Timeout in seconds

HTTP.SetConnectionTimeout(connection_timeout)
Parameters
NameTypeDescrição
connection_timeoutintegerThe timeout in seconds

SetReadWriteTimeoutOptimal​

Sets the HTTP requests global Read and Write Timeout in seconds

HTTP.SetReadWriteTimeout(read_write_timeout)
Parameters
NameTypeDescrição
read_write_timeoutintegerThe timeout in seconds

🚀 Events​

This class doesn't have own events.