cURL to Lua Converter
Convert curl commands to Lua code using LuaSocket. Paste a command and the Lua snippet appears instantly — everything runs in your browser.
- Instant ConversionCode updates as you type
- Multiple Languages40 languages, 61 libraries
- 100% Client SideYour data stays private
How to use this tool
Steps for using the cURL to Code.
- Copy a curl command — from API documentation, or from your browser's DevTools (Network tab → right-click a request → Copy as cURL (bash)).
- Paste it into Enter cURL command. The Lua LuaSocket code appears instantly.
- Set up: Install with
luarocks install luasocketand, for HTTPS,luarocks install luasec. - Run it: Run the script with
lua request.lua. Replace placeholders such asYOUR_TOKENfirst, and check any notes under the editors for curl options that have no LuaSocket equivalent.
Example
GET with headers → Lua LuaSocket
curl 'https://api.example.com/v1/users?page=2' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer YOUR_TOKEN'local http = require("ssl.https")
local ltn12 = require("ltn12")
local response_body = {}
local ok, code, response_headers = http.request({
url = "https://api.example.com/v1/users?page=2",
method = "GET",
headers = {
["Accept"] = "application/json",
["Authorization"] = "Bearer YOUR_TOKEN",
},
sink = ltn12.sink.table(response_body),
})
if not ok then
error(code)
end
print(code)
print(table.concat(response_body))Common use cases
- Lua scripts and tools
- Embedded Lua environments with LuaSocket
Converting curl to Lua LuaSocket
LuaSocket provides HTTP for Lua; with LuaSec (ssl.https) it supports HTTPS.
The converter reads the curl command the way curl does — the method (-X), headers (-H), request bodies (-d, --data-raw, --json, -F), query strings, basic auth (-u) and cookies — and writes the equivalent LuaSocket code. Options that have no LuaSocket equivalent are listed under the editors rather than silently dropped.
Limitations
- The code is a starting point: add timeouts, retries and error handling for production use.
- Secrets in the curl command are copied into the code — move them to environment variables before committing.
Frequently asked questions
Why require ssl.https?
LuaSocket's socket.http only speaks plain HTTP; LuaSec's ssl.https adds HTTPS.
Why set Content-Length?
LuaSocket doesn't calculate it for a source body, so the code sets it from the body length.
Is my curl command sent to a server?
No. The conversion runs entirely in your browser, so tokens and passwords in the command never leave your device. Still, replace real secrets before sharing the generated code.