curl Converter
Paste the curl command from your API docs or your browser's network panel and choose fetch, Python or axios. Headers, body, form fields, basic authentication and query options are carried across.
Nothing is sent. The command is only read and rewritten.
Worked examples
JSON post to fetch
curl -X POST https://api.test/u -H 'Content-Type: application/json' -d '{"a":[1,2]}'
const response = await fetch("https://api.test/u", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ "a": [ 1, 2 ] }) }); console.log(response.status); console.log(await response.text());
The JSON string became an object inside JSON.stringify.
About curl Converter
API documentation and browser developer tools both share requests as curl commands. It is a handy common language, but you usually need the same call in your own code. Retyping the headers and the body, getting the quoting right and remembering what each flag meant is slow work that is easy to get wrong.
Paste the command and choose JavaScript fetch, Python requests or axios. The command is read the way a shell would read it, including single and double quotes, $'...' strings and backslash line breaks, and the options that change the request are carried across: method, headers, data in all its forms, JSON data, form fields, basic authentication, user agent, referer and cookies, and the option that turns a body into a query string. A JSON body is written as an object instead of an escaped string. Flags that do not change the request are listed so you know they were left out.
How to use curl Converter
- Paste the curl command, including its continuation lines.
- Choose fetch, Python or axios.
- Read the code and any notes about options that were not carried over.
- Copy it into your project and add your real values and error handling.
Common uses
- Reproducing an API example from documentation in your language
- Turning a request copied from a browser network panel into code
- Moving a debugging command into a test
- Learning what a long curl command actually sends
Frequently asked questions
Does it send the request?
No. The command is only read and rewritten as code. Nothing is run.
Why is a Content-Type header added?
When curl sends data with -d and no Content-Type, it uses application/x-www-form-urlencoded. The code includes that header so it behaves the same.
Which curl options are understood?
Method (-X), headers (-H), data (-d and its variants, --data-urlencode), --json, form fields (-F), basic authentication (-u), user agent (-A), referer (-e), cookies (-b), -G, -I and --url. Others are listed as not carried over.
How are file uploads handled?
A form field such as [email protected] is shown as a comment for fetch, because a path on one machine means nothing to the code. In Python it opens the file.
Why does the JSON body look reformatted?
When the body is JSON and the Content-Type says so, it is written as an object so it is easy to read and edit. The data sent is the same.