http
The http library provides functions for making asynchronous web requests.
http.Get(string: url, table: headers, function: callback)
Performs an asynchronous HTTP GET request.
url: The URL to send the request to.
headers: A table of request headers (e.g., {["Content-Type"] = "application/json"}).
callback: A function to be called with the response body (as a string) when the request is complete.
local headers = {
["Accept"] = "*/*",
["User-Agent"] = "MySuperSecureClient/1.0"
}
http.Get("https://api.example.com/data", headers, function(response)
if response then
print("Received data:", response)
else
print("The request failed.")
end
end)
http.Post(string: url, table: headers, string: body, function: callback)
Performs an asynchronous HTTP POST request.
url: The URL to send the request to.
headers: A table of request headers.
body: The string data to send in the request body.
callback: A function to be called with the response body (as a string) when the request is complete.
local headers = {
["Content-Type"] = "application/json"
}
local json_body = '{"username": "MyUser", "score": 100}'
http.Post("https://api.example.com/submit", headers, json_body, function(response)
if response then
print("Server responded:", response)
else
print("The POST request failed.")
end
end)
Last updated