Skip to main content
Version: latest - a1.7.0 βš–οΈ

🌐 HTTP

HTTP Requests Interface

info

🟦 Authority: This 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.

Usage​

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
tableRequestSyncMakes a synchronous HTTP Request

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, content_type, compress, data, headers, callback)
TypeParameterDefault ValueDescription
stringuriThe main URI
stringendpoint/The endpoint
stringmethodGETThe HTTP Method to be used
stringdata Payload
stringcontent_typeapplication/jsonThe Content Type to be used
booleancompressfalseWhether or not to compress the content with gzip
tableheaders{}The Headers to be used
functioncallbacknilThe 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 a table in the format { Status, Data }

HTTP.Request(uri, endpoint, method, content_type, compress, data, headers)
TypeParameterDefault ValueDescription
stringuriThe main URI
stringendpoint/The endpoint
stringmethodGETThe HTTP Method to be used
stringdata Payload
stringcontent_typeapplication/jsonThe Content Type to be used
booleancompressfalseWhether or not to compress the content with gzip
tableheaders{}The Headers to be used