How to Convert cURL to Code: Step-by-Step Tutorial
This tutorial walks through four practical examples of converting cURL commands into working code, from a simple GET request to authenticated requests with JSON bodies. Each example shows what to paste, what to expect, and what the output looks like.
Follow along: Open the cURL to Code Converter in another tab and paste each example as you read.
Table of Contents
Step 1: Convert a Simple GET Request
Start with the most basic case โ a GET request with a query parameter and an Accept header:
curl https://api.example.com/v1/users?limit=10 -H "Accept: application/json"
Paste this into the converter. You should see:
- The Request Model tab shows method
GET, the query parameterlimit=10extracted separately, and the Accept header. - The fetch tab shows a clean
fetch()call with the headers object. - The Python tab shows
requests.request("GET", url, headers=headers).
This is the simplest conversion โ no body, no auth, just URL + headers.
Step 2: Convert a JSON POST Request
Now try a POST request with a JSON body and a bearer token:
curl -X POST "https://api.example.com/v1/users" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer abcdefghijklmnopqrstuvwxyz123456" \
--data-raw '{"name":"Bill","role":"admin"}'
Key things to observe:
- The parser detects the JSON content type and parses the body into a structured object
- The Authorization header value is masked by default โ you will see
<REDACTED>in the output - In the Python output, the body uses
json=payloadinstead ofdata=, because JSON was detected - In the fetch output, the body is wrapped in
JSON.stringify()
Toggle Mask Secrets off to see the real token value in the output.
Step 3: Convert a Form POST with Multiple -d Flags
This example uses form-urlencoded data with separate -d flags for each field:
curl "https://api.example.com/login" -X POST \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "username=bill" -d "password=supersecret"
What the converter does:
- Detects the form content type and combines the two
-dflags intousername=bill&password=supersecret - Shows a warning: "Multiple -d flags detected; concatenated with &"
- Masks the password value in the output (since "password=" is a recognized secret pattern)
- In Python, uses
data=instead ofjson=
Step 4: Convert a Request with Basic Auth and Options
This example combines basic authentication, redirect following, and insecure TLS:
curl -L -k -u user:pass https://example.com/private -H "Accept: */*"
Check the Request Model tab to verify:
auth.typeis"basic"with the username and password extractedoptions.followRedirectsistrue(from-L)options.insecureTLSistrue(from-k)
Each language handles these differently:
- Python: Uses
auth=(user, pass)andverify=False - Go: Uses
req.SetBasicAuth() - PHP: Uses
CURLOPT_USERPWDandCURLOPT_FOLLOWLOCATION
Using the Toggle Options
Error Handling
Turn on the Error Handling toggle to wrap the generated code in try/catch blocks (or language-appropriate error handling). This is recommended when generating code for production use.
Pretty JSON
When enabled, JSON bodies in the output are formatted with indentation. When off, they appear as compact single-line strings.
Indent Size
Choose between 2-space and 4-space indentation to match your project's style.
Using the Extra Copy Buttons
Below the output, four utility buttons let you copy specific parts:
- Copy URL: Just the URL from the parsed command
- Copy Headers JSON: The headers as a JSON object โ useful for pasting into Postman or other tools
- Copy Body: Just the request body
- Copy Normalized cURL: A cleaned-up version of your cURL command with sorted headers and consistent formatting
Exporting to Postman
Select the Postman tab to generate a Postman Collection v2.1 JSON file. Copy the output, save it as a .json file, and import it into Postman using File โ Import. The collection includes the method, URL, headers, and body from your cURL command.
Try all four examples: The converter includes a built-in Examples dropdown that loads each test case with one click.
Open cURL to Code Converter โ