Method Global:HttpRequest [-] [+]
Performs a non-blocking HTTP request.
When the passed callback function is called, the parameters (status, body, headers)
are passed to it.
-- GET example (prints a random word)
HttpRequest("GET", "https://random-word-api.herokuapp.com/word", function(status, body, headers)
print("Random word: " .. string.sub(body, 3, body:len() - 2))
end)
-- POST example with JSON request body
HttpRequest("POST", "https://jsonplaceholder.typicode.com/posts", '{"userId": 1,"title": "Foo","body": "Bar!"}', "application/json", function(status, body, headers)
print(body)
end)
-- Example with request headers
HttpRequest("GET", "https://postman-echo.com/headers", { Accept = "application/json", ["User-Agent"] = "Eluna Lua Engine" }, function(status, body, headers)
print(body)
end)
Synopsis
HttpRequest( httpMethod, url, function )
HttpRequest( httpMethod, url, headers, function )
HttpRequest( httpMethod, url, body, contentType, function )
HttpRequest( httpMethod, url, body, contentType, headers, function )
Arguments
string httpMethod
The HTTP method to use (possible values are:
"GET"
,"HEAD"
,"POST"
,"PUT"
,"PATCH"
,"DELETE"
,"OPTIONS"
).
string url
The URL to query.
table headers
A table with string key-value pairs containing the request headers.
string body
The request's body (only used for POST, PUT and PATCH requests).
string contentType
The body's content-type.
function function
Function that will be called when the request is executed.
Returns
Nothing.