-
Notifications
You must be signed in to change notification settings - Fork 0
Class: HTTPRequestBuilder
The HTTPRequestBuilder class was created as an abstraction over sending HTTP requests.
It simplifies sending HTTP requests, makes it easier to understand.
@argument
URL (string) - The URL link that will be used to send the request.
@argument
Method (enum METHODS
) - The method through which the request will be sent.
Example
local req = HTTPRequestBuilder:new("https://google.com", METHODS.GET)
@description
Sets content type of request
@argument
Type (enum MIME_TYPES
) - MIME type of content
Example
req:SetContentType(MIME_TYPES.JSON)
@description
Sets header value of request
@argument
HeaderName (string) - Name of header
@argument
HeaderValue (string) - Value of header
Example
req:SetHeader("Accept", MIME_TYPES.JSON)
@description
Sets callback of request
@argument
Callback (function with arguments: object HTTPResponse) - Function, that calls when we got response of server
Example
req:SetCallback(function(res)
dump("res", res)
end)
@description
Sets body of request
@argument
Body (any) - Body
Example
req:SetBody({
example_key: "Hello, world!"
}) -- It will be converted to a string when sent
@description
Sets function, that will be send HTTP request
@default
HTTP
@argument
HTTPFunction (function) - function, that will be send HTTP request
Example
require("chttp") -- https://github.com/timschumi/gmod-chttp
req:SetHTTP(CHTTP)
@description
Sends HTTP request
Example
HTTPRequestBuilder:new("https://google.com/", METHODS.GET)
:SetCallback(function(res)
dump("response", res)
end)
:Send()