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:

bash
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):

go
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

FlagDescriptionSupported
-X / --requestHTTP method (GET, POST, PUT, etc.)Yes
-H / --headerRequest header (can repeat)Yes
-d / --data / --data-rawRequest body / payloadYes
-u / --userBasic auth (user:password)Yes
-k / --insecureSkip TLS certificate verificationYes
--urlExplicit URL flagYes
Positional URLURL without a flagYes
Line continuations (\)Multi-line cURL commandsYes

Language Comparison

LanguageLibraryAsync?Install
Gonet/http (stdlib)No (goroutines)Built-in
PythonrequestsNo (use httpx for async)pip install requests
JavaScriptFetch APIYes (async/await)Built-in (Node 18+)
PHPcURL extensionNoBuilt-in
RubyNet::HTTP (stdlib)NoBuilt-in

Common Use Cases

  • API documentationAPI docs show cURL examples — convert them to your language instantly without manual translation.
  • Debugging HTTP requestsBrowser DevTools lets you copy requests as cURL — paste here to get runnable code.
  • Migrating shell scriptsConvert curl-based shell scripts to idiomatic language-specific HTTP clients.
  • Learning HTTP clientsSee how the same request looks across different languages and libraries side-by-side.

Frequently Asked Questions

Yes. Line continuations with backslash (\) are handled automatically — paste the full multi-line command.

Yes. The -u user:password flag is converted to a Base64-encoded Authorization: Basic header in Go, or passed as the auth= parameter in Python.

NewRequestWithContext is the idiomatic Go approach since Go 1.13. It lets you pass a context for cancellation and timeouts, which is best practice for production HTTP clients.

Multipart form uploads (-F flag) are not yet supported. The tool focuses on JSON/text body requests.

Related Tools