cURL to Code
Convert any cURL command to idiomatic code in Go, Python, JavaScript, PHP or Ruby.
What is cURL?
cURL (Client URL) is a command-line tool and library for transferring data using URLs. It supports dozens of protocols — HTTP, HTTPS, FTP, SMTP and more. For developers, cURL is the universal way to make HTTP requests from the terminal, test APIs, and inspect server responses without writing any code.
API documentation almost always includes cURL examples because cURL works on every OS and is the lowest common denominator. But writing production code with cURL commands is impractical — you need idiomatic HTTP clients in your language. This tool converts any cURL command to ready-to-run code in Go, Python, JavaScript, PHP, or Ruby.
cURL to Go Example
Input cURL:
curl -X POST https://api.example.com/users \
-H "Authorization: Bearer token123" \
-H "Content-Type: application/json" \
-d '{"name":"Ravi","role":"admin"}'Generated Go (net/http):
package main
import (
"context"
"fmt"
"net/http"
"strings"
)
func main() {
ctx := context.Background()
body := strings.NewReader(`{"name":"Ravi","role":"admin"}`)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, "https://api.example.com/users", body)
if err != nil { panic(err) }
req.Header.Set("Authorization", "Bearer token123")
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil { panic(err) }
defer resp.Body.Close()
fmt.Println(resp.Status)
}Supported cURL Flags
| Flag | Description | Supported |
|---|---|---|
| -X / --request | HTTP method (GET, POST, PUT, etc.) | Yes |
| -H / --header | Request header (can repeat) | Yes |
| -d / --data / --data-raw | Request body / payload | Yes |
| -u / --user | Basic auth (user:password) | Yes |
| -k / --insecure | Skip TLS certificate verification | Yes |
| --url | Explicit URL flag | Yes |
| Positional URL | URL without a flag | Yes |
| Line continuations (\) | Multi-line cURL commands | Yes |
Language Comparison
| Language | Library | Async? | Install |
|---|---|---|---|
| Go | net/http (stdlib) | No (goroutines) | Built-in |
| Python | requests | No (use httpx for async) | pip install requests |
| JavaScript | Fetch API | Yes (async/await) | Built-in (Node 18+) |
| PHP | cURL extension | No | Built-in |
| Ruby | Net::HTTP (stdlib) | No | Built-in |
Common Use Cases
- ▸API documentation — API docs show cURL examples — convert them to your language instantly without manual translation.
- ▸Debugging HTTP requests — Browser DevTools lets you copy requests as cURL — paste here to get runnable code.
- ▸Migrating shell scripts — Convert curl-based shell scripts to idiomatic language-specific HTTP clients.
- ▸Learning HTTP clients — See how the same request looks across different languages and libraries side-by-side.