Skip to content

cURL to Code Converter - fetch, Python, Go, PHP

cURL command
JavaScript fetch

Convert cURL commands to code

API docs give their examples as curl commands, and every browser can copy a network request as one. Rewriting that by hand means re-typing headers, re-escaping quotes and looking up how each library sends JSON or a multipart form. Paste the command here and get code for JavaScript fetch, Axios, Python requests, Go net/http, PHP cURL or Node.js https.

How to use it

Paste a command and pick a language. Switching language re-renders the same request, so you can compare them side by side. If the command cannot be read, such as no URL or a flag with no value after it, the error says which.

Example

Input:

curl 'https://api.example.com/v1/orders' \
  -H 'Authorization: Bearer sk_test_123' \
  -H 'Content-Type: application/json' \
  --data-raw '{"product":"tea","qty":2}'

Output (Python requests):

import requests

headers = {
    "Authorization": "Bearer sk_test_123",
}

json_data = {
    "product": "tea",
    "qty": 2,
}

response = requests.post("https://api.example.com/v1/orders", headers=headers, json=json_data)
print(response.status_code, response.text)

The method is POST because the command sends data, and the JSON body becomes a Python dictionary passed with json=, which also sets the Content-Type header for you.

How curl options map to code

  • Method: taken from -X. Without it, requests with data become POST, -I becomes HEAD and everything else is GET.
  • Headers: each -H becomes a header. -b becomes a Cookie header, -A a User-Agent.
  • Body: several -d flags are joined with &, as curl does. --json also adds JSON Content-Type and Accept headers.
  • Query string: with -G, the data is appended to the URL instead of sent as a body.
  • Forms and files: -F name=value and -F file=@path become multipart form data with a file upload.
  • Basic auth: -u user:pass uses each library's auth option or an Authorization header.
  • TLS and redirects: -k turns off certificate checks and -L follows redirects where the library needs to be told. Browser fetch cannot skip certificate checks, so the fetch output only adds a comment saying so.

Tips for browser requests

Requests copied from DevTools carry headers the browser adds itself: sec-ch-ua, sec-fetch-*, accept-language, priority. APIs rarely need them, so delete them to keep the code readable. Keep authorization, content-type, cookies and custom x- headers. If the request still fails outside the browser, the server is probably checking a cookie or CSRF token that has since expired. To see what a server sends back, try the HTTP headers inspector.

Related Tools

Frequently Asked Questions

How do I copy a request as cURL from my browser?
Open DevTools, go to the Network tab, right-click the request and choose Copy, then Copy as cURL. On Windows, Chrome and Edge offer cmd and bash versions: pick bash. The cmd version escapes quotes with ^, which this parser does not undo. Firefox and Safari have the same option in their network panels.
Which cURL options are supported?
-X/--request, -H/--header, -d/--data, --data-raw, --data-binary, --data-urlencode, --json, -u/--user, -F/--form, -b/--cookie, -A/--user-agent, -e/--referer, -G/--get, --url, -L/--location, -k/--insecure and -I/--head. Combined short flags such as -sSL work too. Options that only affect curl's own output, such as --compressed or -s, are ignored. A body read from a file with -d @body.json is not loaded (the page cannot see your files), so paste the file's contents inline instead.
Does it handle quotes and line continuations?
Yes, bash-style. Single quotes, double quotes, backslash escapes, $'...' strings (Chrome uses these for bodies containing quotes or newlines) and trailing-backslash line continuations are all handled, and so are cmd-style ^ line endings. cmd's ^" quote escaping and PowerShell backticks are not.
Why is my JSON body shown as an object?
When the Content-Type is JSON (or you used --json) and the body parses as JSON, the code uses the language's own JSON handling, such as JSON.stringify in fetch or json= in Python requests. Any other body is sent as a plain string, the way curl sends it.
Is it safe to paste commands with tokens or cookies?
The conversion runs in your browser and nothing is sent to a server. Still, treat the generated code like the original command: remove real tokens and cookies before sharing it or committing it.