How to Convert cURL Commands to Python, JavaScript, Go, and More
API documentation almost always gives you a cURL command. But your production code doesn't use cURL — it uses requests, fetch, or net/http. Here's how to bridge that gap instantly.
Why cURL Is the Universal API Example
cURL is installed on virtually every developer machine — macOS, Linux, and Windows (since Windows 10). It's the lowest common denominator for showing how an API works: copy the command, paste it into a terminal, and see the response.
That's why Stripe, Twilio, GitHub, and almost every API documentation starts with cURL. But when you need to integrate that API into your application, you need the same request in your language's HTTP library — with proper headers, authentication, body encoding, and error handling.
What a cURL Command Contains
A cURL command packs a complete HTTP request into a single line. Here's what each flag maps to:
- -X / --request: The HTTP method (GET, POST, PUT, DELETE, PATCH)
- -H / --header: Request headers — Content-Type, Authorization, Accept, custom headers
- -d / --data: The request body (JSON, form data, raw text)
- -u / --user: Basic authentication credentials (username:password)
- -F / --form: Multipart form data (for file uploads)
- -k / --insecure: Skip SSL certificate verification (development only)
- -L / --location: Follow redirects automatically
Converting to Python (requests)
Python's requests library maps almost 1:1 to cURL flags. The URL goes into the first argument, headers into a dict, and the body into json= or data=.
The main gotcha: cURL's -d with a JSON Content-Type should use json= in requests (which auto-sets the header), not data=. Using data= with a string sends it as-is, which works but skips the automatic serialisation.
Converting to JavaScript (fetch)
The Fetch API is available in all modern browsers and Node.js 18+. The mapping is: URL as the first argument, and an options object with method, headers, and body.
Unlike cURL, fetch doesn't follow redirects for POST requests by default, and it doesn't throw on HTTP error status codes — you need to check response.ok yourself.
Converting to Go (net/http)
Go's standard library net/http is more verbose than Python or JavaScript, but it gives you full control. You create a request with http.NewRequest, set headers, and execute it with a client.
The conversion is mechanical but requires proper error handling, body closing, and response reading — which is where a converter saves the most time compared to writing it from scratch.
Common Pitfalls When Converting Manually
- Missing Content-Type: cURL with
-ddefaults toapplication/x-www-form-urlencoded, not JSON. If the API expects JSON, you need the explicit header. - Shell escaping: cURL commands copied from docs often use single quotes, backslashes, and line continuations that need to be parsed correctly before converting.
- Auth handling:
-u user:passis Basic auth (Base64-encoded). Some languages have built-in Basic auth support; others need manual header construction. - Cookie handling: cURL's
-bflag needs to be mapped to cookie headers or a cookie jar in your language.
Convert any cURL command instantly
Paste a cURL command and get clean, production-ready code in Python, JavaScript, Go, PHP, and more.
Open cURL Converter