Functions
| Function | Returns | Description |
|---|---|---|
http.get(url [, options], callback) | bool, error? | GET request |
http.post(url, body [, options], callback) | bool, error? | POST request |
Options
| Field | Type | Default | Description |
|---|---|---|---|
headers | table | {} | Request headers as {["Key"] = "Value"} |
timeout | number | 10 | Timeout in seconds |
Response
The callback receives a response table:| Field | Type | Description |
|---|---|---|
status | number | HTTP status code |
body | string | Response body |
headers | table | Response headers |
Example
http.get('https://api.example.com/data', { timeout = 5 }, function(r)
if r.status == 200 then
local data = json.decode(r.body)
print(data.result)
end
end)
http.post('https://api.example.com/log', json.encode({ event = 'loaded' }), {
headers = { ['Content-Type'] = 'application/json' }
}, function(r)
print('posted:', r.status)
end)