Skip to main content
Version: latest - a1.73.x โš–๏ธ

๐ŸŒ HTTP

HTTP Requests Interface.

๐Ÿ—ฟStatic Class
This is a Static Class. Access it's methods directly with .. It's not possible to spawn new instances.
๐Ÿ’‚Authority
This static class can be accessed on both ๐ŸŸง Client and ๐ŸŸฆ Server side.
๐Ÿง‘โ€๐Ÿ’ปAPI Source
This page is auto-generated! The Functions, Properties and Events described here are defined in our GitHub's API Repository! Feel free to commit suggestions and changes to the source .json API files!

๐ŸŽ’ Examplesโ€‹

Server/Index.lua
-- Makes an asynchronous HTTP Request
HTTP.RequestAsync("127.0.0.1:7777", "/", HTTPMethod.GET, "", "application/json", false, {}, function(status, data)
Console.Log(status) -- 200
Console.Log(data) -- "{"players_count":0,"server_name":"nanos world server"}"

-- TIP: You can parse it if it's a json return as well
local json_ret = JSON.parse(data)
end)
Server/Index.lua
-- 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"}"
tip

All requests are thread safe! ๐Ÿฅณ This means that callbacks are returned on the main thread!

๐Ÿ—ฟ Static Functionsโ€‹

ReturnsNameDescription
Makes a synchronous HTTP Request.

The request will be made synchronously and will freeze the server until it's done.
Makes an asynchronous HTTP Request
Sets the global Connection Timeout in seconds
Sets the global Read and Write Timeout in seconds

Request

Makes a synchronous HTTP Request.

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

โ€” Returns ().

local ret = HTTP.Request(uri, endpoint?, method?, data?, content_type?, compress?, headers?)
TypeParameterDefaultDescription
uri Required parameter The main URI (the base address)
endpoint?The endpoint
method?HTTPMethod.GETThe HTTP Method to be used
data?Payload
content_type?application/jsonThe Content Type to be used
compress?falseWhether or not to compress the content with gzip
headers?{}The Headers to be used

RequestAsync

Makes an asynchronous HTTP Request.

The request will be made asynchronously and returned safetly 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?)
TypeParameterDefaultDescription
uri Required parameter The main URI (the base address)
endpoint?The endpoint
method?HTTPMethod.GETThe HTTP Method to be used
data?Payload
content_type?application/jsonThe Content Type to be used
compress?falseWhether or not to compress the content with gzip
headers?{}The Headers to be used
callback?nilThe result

SetConnectionTimeout

Sets the global Connection Timeout in seconds

HTTP.SetConnectionTimeout(connection_timeout)
TypeParameterDefaultDescription
connection_timeout Required parameter The timeout in seconds

SetReadWriteTimeout

Sets the global Read and Write Timeout in seconds

HTTP.SetReadWriteTimeout(read_write_timeout)
TypeParameterDefaultDescription
read_write_timeout Required parameter The timeout in seconds

๐Ÿš€ Eventsโ€‹

This class doesn't have own events.