HTTP
Utilizada para fazer requisições utilizando o protocolo HTTP.
Atalhos
Métodos
GET
-- @param url String containing the url.
-- @param @optional headers Table containing the headers of the request.
-- @param @optional body String containing the JSON encoded body.
-- @return a table containing headers, status, text.
http.get(url, headers, body)-- example usage:
local request = http.get("https://httpbin.org/get")
local body = request.text
local headers = request.headers
local status = request.status
--[[
request value:
{
headers = {
["access-control-allow-credentials"] = "true",
["access-control-allow-origin"] = "*",
connection = "keep-alive",
["content-length"] = "222",
["content-type"] = "application/json",
date = "Fri, 27 Dec 2024 20:55:39 GMT",
server = "gunicorn/19.9.0"
},
status = 200,
text = '{\n "args": {}, \n "headers": {\n "Accept": "*/*", \n "Host": "httpbin.org", \n "X-Amzn-Trace-Id": "Root=1-676f1449-635d770f2b8b549173c3fa96"\n }, \n "origin": "186.235.83.146", \n "url": "https://httpbin.org/get"\n}\n'
}
--]]POST
-- @param url String containing the url.
-- @param @optional headers Table containing the headers of the request.
-- @param @optional body String containing the JSON encoded body.
-- @return a table containing headers, status, text.
http.post(url, headers, body)-- example usage:
local request = http.post(
"https://httpbin.org/post",
{ ["Content-Type"] = "application/json" },
json.encode({key = "value"})
)
local body = request.text
local headers = request.headers
local status = request.statusPUT
-- @param url String containing the url.
-- @param @optional headers Table containing the headers of the request.
-- @param @optional body String containing the JSON encoded body.
-- @return a table containing headers, status, text.
http.put(url, headers, body)
-- example usage:
local request = http.put(
"https://httpbin.org/put",
{ ["Content-Type"] = "application/json" },
nil
)
local body = request.text
local headers = request.headers
local status = request.statusDELETE
-- @param url String containing the url.
-- @param @optional headers Table containing the headers of the request.
-- @param @optional body String containing the JSON encoded body.
-- @return a table containing headers, status, text.
http.delete(url, headers, body)-- example usage:
local request = http.delete(
"https://httpbin.org/delete",
{ ["Content-Type"] = "application/json" },
nil
)
local body = request.text
local headers = request.headers
local status = request.statusPATCH
-- @param url String containing the url.
-- @param @optional headers Table containing the headers of the request.
-- @param @optional body String containing the JSON encoded body.
-- @return a table containing headers, status, text.
http.patch(url, headers, body)-- example usage:
local request = http.patch("https://httpbin.org/patch")
local body = request.text
local headers = request.headers
local status = request.status