05-07-26
HTTP Request Sender Lua Script
This Lua script for hardware input allows you to send HTTP requests with a hotkey. Configure the URL, method, headers, and body, and receive feedback on the request's status. Useful for webhooks and A
Question
Can you provide a Rebind Lua script that sends HTTP requests on a hotkey press?
Rebind AI
[
{
"role": "user",
"content": "HTTP request sender on hotkey press"},
{
"role": "assistant",
"content": "lua -- rebind: name=HTTP Request Sender -- rebind: permission=net
local cfg = UI.Schema({ hotkey = UI.Keybind("F9", { label = "Send Request" }), url = UI.Text("https://example.com/webhook", { label = "URL", maxLength = 200 }), method = UI.Select("POST", { "GET", "POST", "PUT", "PATCH", "DELETE" }), body = UI.Text("", { label = "Request Body (JSON)", maxLength = 500 }), headers = UI.Text("", { label = "Headers (JSON)", maxLength = 300, placeholder = '{"Content-Type":"application/json"}' }), timeout = UI.Slider(5000, { min = 1000, max = 30000, suffix = "ms", label = "Timeout" }), })
Bind( cfg.hotkey, Async(function() if not cfg.url or cfg.url == "" then UI.Notify("URL is required", "error") return false end
local headers = {}
if cfg.headers and cfg.headers ~= "" then
pcall(function()
headers = JSON.Parse(cfg.headers)
end)
end
local response
local start = System.Time()
if cfg.method == "GET" then
response = Net.Get(cfg.url, headers, { timeout = cfg.timeout })
elseif cfg.method == "POST" then
response = Net.Post(cfg.url, cfg.body or "", headers, { timeout = cfg.timeout })
elseif cfg.method == "PUT" then
response = Net.Put(cfg.url, cfg.body or "", headers, { timeout = cfg.timeout })
elseif cfg.method == "PATCH" then
response = Net.Patch(cfg.url, cfg.body or "", headers, { timeout = cfg.timeout })
elseif cfg.method == "DELETE" then
response = Net.Delete(cfg.url, headers, { timeout = cfg.timeout })
end
local elapsed = System.Time() - start
if response then
local status = response.status
local variant = status >= 200 and status < 300 and "success" or "error"
UI.Notify(cfg.method .. " " .. status .. " (" .. elapsed .. "ms)", variant)
Log.Info("Response: " .. response.body:sub(1, 200))
else
UI.Notify("Request failed", "error")
end
return false
end)
)
**How it works:**
This script provides a configurable HTTP request sender accessible via a hotkey:
- **Hotkey binding** — Press F9 (or configured key) to trigger the request
- **Method selection** — Choose GET, POST, PUT, PATCH, or DELETE
- **Custom headers** — Paste JSON headers like `{"Authorization":"Bearer token","Content-Type":"application/json"}`
- **Request body** — Include JSON body for POST/PUT/PATCH methods
- **Timeout control** — Adjust HTTP timeout (default 5 seconds)
- **Response feedback** — Shows HTTP status code and elapsed time, plus first 200 chars of response in logs
**Common use cases:**
- Trigger webhooks (Discord, Slack, custom APIs)
- Test API endpoints during development
- Send commands to external services
- Integrate with smart home or game servers
Wrap with `Async()` so the HTTP call doesn't block input, and responses display in notifications.
**Learn more**
- [Net](https://docs.rebind.gg/sdk-reference.html#net)
- [Bind](https://docs.rebind.gg/sdk-reference.html#bind)
- [UI](https://docs.rebind.gg/sdk-reference.html#ui)
- [Async](https://docs.rebind.gg/sdk-reference.html#async)
"}