Pages

Topics

Tools

↑↓navigate↵openescclose
Encoding & Security

cURL to Code

Paste a curl command and get JavaScript fetch, TypeScript, Python requests, or Go net/http code with headers and body intact.

Runs entirely in your browser — nothing you paste is uploaded.

Presets
1 lines
POST2 headers79 body bytes
https://api.example.com/v1/orders
  • Content-Type: application/json
  • Accept: application/json
live
JavaScript · fetch
531 chars · 26 lines
const options = {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Accept": "application/json",
  },
  body: JSON.stringify({
    "customer_id": "cus_1042",
    "items": [
      {
        "sku": "SOFT-01",
        "qty": 2
      }
    ],
    "currency": "USD"
  }),
};

const response = await fetch("https://api.example.com/v1/orders", options);

if (!response.ok) {
  throw new Error(`Request failed: ${response.status} ${response.statusText}`);
}

const data = await response.json();
console.log(data);

Flags that have no equivalent in the target language — output files, proxies, retries — are reported on the left instead of being dropped silently.

curl flag cheat sheet

quick reference
-X POST
Sets the method; curl already sends POST as soon as a -d body is present, so -X is only needed for PUT, PATCH, or DELETE.
-H 'Content-Type: application/json'
Repeat -H for each header. Without a Content-Type, servers treat a JSON body as form data or plain text.
-d '{"a":1}' / --data-raw
-d strips newlines and encodes the body; --data-raw sends it untouched, which is what you want for JSON.
-u user:pass
HTTP Basic auth. The pair is base64-encoded into an Authorization header, which is only safe over HTTPS.
-A / -b
-A sets User-Agent and -b sends a Cookie header; both appear in the generated code as ordinary headers.
-L -sS -o out.json
Location-follow, silent but show errors, and write to a file — output and transport flags that do not exist in fetch code.
All Node.js guides