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
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(value: any) → booleanReturns true if the value is an HttpResponse
convertHttpResponseToString
HttpPromise.convertHttpResponseToString(value: HttpResponse) → stringConverts an http response to a string for debugging
json
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: {Body: string}) → tableDecodes JSON from the response