nanos world API Reference Unofficial documentation
Static function Server

HTTP.Request

Makes a synchronous HTTP Request.<br/><br/>The request will be made synchronously and will freeze the server until it's done.

Syntax

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

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

Returns

  • table
    Table fields
    • Status integer
    • Data string
    • Headers table

Examples

Makes an asynchronous 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"