Skip to main content
Version: bleeding-edge 🩸

🌐 HTTP

HTTP Requests Interface.

πŸ’‚Authority
This static class can be accessed only on 🟦 Server.
πŸ—ΏStatic Class
This is a Static Class. You can access it's methods directly with .. It is not possible to initialize or create new instances.

πŸŽ’ Examples​

Server/Index.lua
-- Makes an asynchronous HTTP Request
HTTP.Request("localhost:7777", "/", "GET", "", "application/json", false, {}, function(status, data)
Package.Log(status) -- 200
Package.Log(data) -- 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.RequestSync("localhost:7777", "/", "GET", "", "application/json", false, {})

Package.Log(ret.Status) -- 200
Package.Log(ret.Data) -- nanos world server
tip

All requests are thread safe! πŸ₯³

πŸ—Ώ Static Functions​

ReturnsNameDescription
RequestMakes an asynchronous HTTP Request
table RequestSyncMakes a synchronous HTTP Request.

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

Request​

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.Request(uri, endpoint?, method?, data?, content_type?, compress?, headers?, callback?)
TypeParameterDefaultDescription
string uriThe main URI
string endpoint?/The endpoint
string method?GETThe HTTP Method to be used
string data?Payload
string content_type?application/jsonThe Content Type to be used
boolean compress?falseWhether or not to compress the content with gzip
table headers?{}The Headers to be used
function callback?nilThe result will be called in the format `function(status, data)`

RequestSync​

Makes a synchronous HTTP Request.

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


Returns table (in the format { Status: number, Data: string })
local ret = HTTP.RequestSync(uri, endpoint?, method?, data?, content_type?, compress?, headers?)
TypeParameterDefaultDescription
string uriThe main URI
string endpoint?/The endpoint
string method?GETThe HTTP Method to be used
string data?Payload
string content_type?application/jsonThe Content Type to be used
boolean compress?falseWhether or not to compress the content with gzip
table headers?{}The Headers to be used

πŸš€ Events​

This entity doesn't have own events.