HTTP requests library¶
LuaConnector has built-in http requests library
Functions¶
request [#1]¶
Prepares an http request:
http.request(method, url, callback)
Arguments¶
stringmethod- an http method. Available methods: GET, HEAD, POST, PUT, DELETE, OPTIONS
stringurl- request url
functioncallback- callback function gets called when a response has been acquired. Has two arguments:
httpRequest- current http request object
httpResponse- response from current http request
Returns¶
httpRequesthttp request object
request [#2]¶
Prepares an http request:
http.request(options, callback)
Arguments¶
tableoptions- table of request options
stringmethod- an http method. Available methods: GET, HEAD, POST, PUT, DELETE, OPTIONS
stringurl- request url
tableheaders- request headers
stringcontent- applies only to POST and PUT requests
stringurl- request url
functioncallback- callback function gets called when a response has been acquired. Has two arguments:
httpRequest- current http request object
httpResponse- response from current http request
Returns¶
httpRequesthttp request object
Objects¶
Examples¶
local request = http.request("GET", "https://jsonplaceholder.typicode.com/posts/1", function(req, res)
print(res.content)
end)
request.send()
local options = {
method = "POST",
url = "https://discordapp.com/api/auth/login",
content = json.serialize({email = "", password = ""}),
headers = {
["Content-Type"] = "application/json"
}
}
http.request(options, function(req, res)
print(res.content)
end).send()