Skip to main content

HttpPromise

This item only works when running on the server. Server

Provides a wrapper around HttpService with a promise API

By combining functions in HttpPromise, we can get a generic request result in a very clean way.

local function logToDiscord(body)
	return HttpPromise.request({
		Headers = {
			["Content-Type"] = "application/json";
		};
		Url = DISCORD_LOG_URL;
		Body = HttpService:JSONEncode(data);
		Method = "POST";
	})
	:Then(HttpPromise.decodeJson)
	:Catch(HttpPromise.logFailedRequests)
end

Functions

request

HttpPromise.request(requesttable) → Promise<table>

Decodes JSON from the response

local requestPromise = HttpPromise.request({
	Headers = {
		["Content-Type"] = "application/json";
	};
	Url = DISCORD_LOG_URL;
	Body = HttpService:JSONEncode(data);
	Method = "POST";
})

isHttpResponse

HttpPromise.isHttpResponse(valueany) → boolean

Returns true if the value is an HttpResponse

convertHttpResponseToString

HttpPromise.convertHttpResponseToString(valueHttpResponse) → string

Converts an http response to a string for debugging

json

HttpPromise.json(requesttable | string) → Promise<table>

Makes a GET JSON request and then expects JSON as a result from said request

HttpPromise.json("https://quenty.org/banned/4397833/status")
	:Then(print)

logFailedRequests

HttpPromise.logFailedRequests(
...any--

A list of requests to retrieve. Meant to be used

) → ()

Logs failed requests and any errors retrieved

HttpPromise.json("https://quenty.org/banned/4397833/status")
	:Catch(HttpPromise.logFailedRequests)

decodeJson

HttpPromise.decodeJson(response{Bodystring}) → table

Decodes JSON from the response

Show raw api
{
    "functions": [
        {
            "name": "request",
            "desc": "Decodes JSON from the response\n\n```lua\nlocal requestPromise = HttpPromise.request({\n\tHeaders = {\n\t\t[\"Content-Type\"] = \"application/json\";\n\t};\n\tUrl = DISCORD_LOG_URL;\n\tBody = HttpService:JSONEncode(data);\n\tMethod = \"POST\";\n})\n```",
            "params": [
                {
                    "name": "request",
                    "desc": "",
                    "lua_type": "table"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<table>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 52,
                "path": "src/httppromise/src/Server/HttpPromise.lua"
            }
        },
        {
            "name": "isHttpResponse",
            "desc": "Returns true if the value is an HttpResponse",
            "params": [
                {
                    "name": "value",
                    "desc": "",
                    "lua_type": "any"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 88,
                "path": "src/httppromise/src/Server/HttpPromise.lua"
            }
        },
        {
            "name": "convertHttpResponseToString",
            "desc": "Converts an http response to a string for debugging",
            "params": [
                {
                    "name": "value",
                    "desc": "",
                    "lua_type": "HttpResponse"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 103,
                "path": "src/httppromise/src/Server/HttpPromise.lua"
            }
        },
        {
            "name": "json",
            "desc": "Makes a GET JSON request and then expects JSON as a result from said request\n\n```lua\nHttpPromise.json(\"https://quenty.org/banned/4397833/status\")\n\t:Then(print)\n```",
            "params": [
                {
                    "name": "request",
                    "desc": "",
                    "lua_type": "table | string"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<table>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 120,
                "path": "src/httppromise/src/Server/HttpPromise.lua"
            }
        },
        {
            "name": "logFailedRequests",
            "desc": "Logs failed requests and any errors retrieved\n\n```lua\nHttpPromise.json(\"https://quenty.org/banned/4397833/status\")\n\t:Catch(HttpPromise.logFailedRequests)\n```",
            "params": [
                {
                    "name": "...",
                    "desc": "A list of requests to retrieve. Meant to be used",
                    "lua_type": "any"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 142,
                "path": "src/httppromise/src/Server/HttpPromise.lua"
            }
        },
        {
            "name": "decodeJson",
            "desc": "Decodes JSON from the response",
            "params": [
                {
                    "name": "response",
                    "desc": "",
                    "lua_type": "{ Body: string }"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "table"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 158,
                "path": "src/httppromise/src/Server/HttpPromise.lua"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "HttpPromise",
    "desc": "Provides a wrapper around HttpService with a promise API\n\nBy combining functions in HttpPromise, we can get a generic request result in a very clean way.\n```lua\nlocal function logToDiscord(body)\n\treturn HttpPromise.request({\n\t\tHeaders = {\n\t\t\t[\"Content-Type\"] = \"application/json\";\n\t\t};\n\t\tUrl = DISCORD_LOG_URL;\n\t\tBody = HttpService:JSONEncode(data);\n\t\tMethod = \"POST\";\n\t})\n\t:Then(HttpPromise.decodeJson)\n\t:Catch(HttpPromise.logFailedRequests)\nend\n```",
    "realm": [
        "Server"
    ],
    "source": {
        "line": 23,
        "path": "src/httppromise/src/Server/HttpPromise.lua"
    }
}