All articles
DeveloperSep 10, 2026 · 4 min read

How to Convert a cURL Command to fetch (or Python)

You copied a cURL command from an API doc or your browser's network tab, and now you need it as real code. The mapping is straightforward once you know which flag becomes what — or you can paste it into a converter and skip the busywork.

Convert it instantly

Paste your command into the cURL to Code converter and get JavaScript (fetch) or Python (requests) output you can copy straight into your app. It runs in your browser, so your URLs and tokens never leave your device.

How the flags map

  • URL (the bare argument) → the first argument to fetch() / the url.
  • -X / --request → the HTTP method (defaults to GET, or POST if there's a body).
  • -H / --header → an entry in the headers object.
  • -d / --data → the request body (and implies POST).

A worked example

This cURL command:

curl -X POST https://api.example.com/users -H "Content-Type: application/json" -d '{"name":"Alex"}'

becomes, in JavaScript:

fetch("https://api.example.com/users", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: '{"name":"Alex"}',
})
  .then((res) => res.json())
  .then(console.log);

Tips

  • If the body is JSON, remember to JSON.stringify() an object, or send the raw string as shown.
  • Copy commands from Chrome DevTools → Network → right-click a request → Copy as cURL.
  • Format the response body with our JSON Formatter, and decode any bearer token with the JWT Decoder.

FAQ

Does the converter support Python?

Yes — switch to the Python tab for a requests version of the same call.

Is my command sent to a server?

No — it's parsed entirely in your browser, so your API URLs and tokens stay private.

Try the cURL to Code

Convert a cURL command to JavaScript fetch or Python requests.