cURL to Code

cURL command

Paste any cURL command, straight from a terminal or an API doc. Drafts are parsed locally.
POSTmethod2headers1queryjsonbody
Target language

Generated JavaScript fetch

const options = {
  method: 'POST',
  headers: {
    'content-type': 'application/json',
    'authorization': 'Bearer abc123',
  },
  body: JSON.stringify("{\n  \"qty\": 2,\n  \"sku\": \"A-1\"\n}"),
};

const response = await fetch('https://api.example.com/orders?dryRun=true', options);
const data = await response.json();
console.log(data);

Normalized cURL

curl \
  --request POST \
  --url https://api.example.com/orders?dryRun=true \
  --header 'content-type: application/json' \
  --header 'authorization: Bearer abc123' \
  --data '{
  "qty": 2,
  "sku": "A-1"
}'

cURL to Code

Turn any cURL command into JavaScript fetch, Axios, Python requests, Java, Go, C# or PHP in one click. Paste a command from your terminal or an API doc and get a faithful, copy-paste-ready request.

About this tool

What is it?
DataFormatter cURL to Code is a free online tool that converts a cURL command into JavaScript fetch, Axios, Python requests, Java, Go, C# or PHP.
Who is it for?
Developers who have a working curl command and want the equivalent code in their language of choice.
What makes DataFormatter's tool different?
It parses headers, auth, query and body faithfully and runs locally in the browser, so the request you paste is never uploaded.

Quick start

  1. Copy a cURL command from your terminal, an API doc, or DevTools.
  2. Paste it into the box — the method, URL, headers, auth and body are parsed instantly.
  3. Pick the language you want from the segmented control.
  4. Copy the generated snippet, or grab the Normalized cURL for a reusable canonical version.

What cURL to code generates

  • fetch with explicit method, headers.json, string body and resolved URL.
  • Axios config with method, url, params, headers and data.
  • Python requests.session() style code with headers and json/data kwargs.
  • Java HttpClient with HttpRequest.Builder and a URI built from parts.
  • Go http.NewRequest with headers set and the body wrapped in a reader.
  • C# HttpClient with HttpClientRequestMessage and a StringContent body.
  • PHP using curl_setopt for the URL, method, headers and postfields.

How to convert cURL to code online

  • Export a request as cURL from Chrome DevTools (Network tab → Copy as cURL).
  • Paste it here; the summary chips show what was understood (method, headers, query, body).
  • Choose a dialect that matches your stack and copy the result.
  • Smoke-test the result with the API Tester if you want to see the live response.
cURL command
curl 'https://api.example.com/orders?dryRun=true' \
  -H 'Authorization: Bearer abc123' \
  -d '{"qty": 2}'
JavaScript fetch
fetch("https://api.example.com/orders?dryRun=true", {
  method: "POST",
  headers: { "Authorization": "Bearer abc123" },
  body: '{"qty": 2}'
});

Who converts cURL to code — and when

Reproducing an API call from docs

Docs ship curl samples, your app needs code. Paste once and get a snippet in the language your team actually writes.

Moving from Postman/DevTools to scripted tests

Turn a hand-tested request into a Python or Go snippet for your test suite in seconds.

Onboarding without auth drama

Convert and run against a sandbox — the parsed Authorization header survives, so the snippet works the first time.

Common issues

"That doesn't look like a cURL command"

Why: The paste doesn't start with curl (e.g. it began with 'curl.exe' on Windows, or an env-var prefix).

Fix: Paste the raw command starting at curl. Windows curl.exe is accepted, but drop prefixes like 'Invoke-WebRequest' that use a different syntax.

Missing URL

Why: The command contains no URL token, so nothing can be generated.

Fix: Re-export the request — DevTools always includes the URL.

Body came out as raw text

Why: A payload that isn't valid JSON or k=v pairs is treated as text — correct a lot of the time, surprising for malformed JSON.

Fix: Validate the body with JSON Diff or the validator, then re-paste.

Pro tips

  • Exports from DevTools carry Referer/Cookie/User-Agent headers — those are modeled, so expect them in the output.
  • Basic auth via -u becomes a dedicated auth header rather than a header row.
  • -G turns your --data into query parameters automatically (curl's documented behavior).
  • Keep secrets local: generation never sends your tokens anywhere.

Frequently asked questions

How does a cURL command become code?

The command is parsed by the same tokenizer the API tester uses, so the method, URL, query, headers, auth and body are all recovered faithfully. That structured request is then rendered by a per-language generator.

Which languages are supported?

JavaScript fetch, Axios, Python requests, Java (java.net.http.HttpClient), Go, C# (System.Net.Http) and PHP (cURL). One paste, seven dialects.

My curl uses --compressed or -v. Will import break?

No. Flags this tool doesn't model (like --compressed, -v, --max-time) are ignored gracefully, and the URL, method, headers, data, -u basic auth and -F multipart fields it does understand are preserved.

Does it handle single and double quotes in my shell command?

Yes. The tokenizer handles single-quoted literals (including the '\'' join trick), double quotes, backslash-line continuations, and $'…' ANSI-C escapes like \n — so multi-line curl you copied from a terminal works as-is.

Why is there a Normalized cURL output?

After parsing, the same structured request is rendered back as a canonical curl command. It's useful for sharing a reproducible version of a request you originally pasted with odd quoting.

Is my command uploaded?

No. Parsing and code generation happen entirely in the browser, so API keys and Authorization headers in your paste never leave your machine.

Related tools

Last reviewed September 2026 · DataFormatter team — this tool processes data locally in your browser.