Skip to content

curl to Code Converter

Turn a curl command into clean code.

Paste a full curl command. Line continuations (\) and quoting are handled.

Results

Method
POST
Headers
2
Body
yes
URL

https://api.example.com/v1/users

Headers
Authorization
Bearer sk_test_123
Content-Type
application/json
Body
{"name":"Ada","role":"admin"}

How the curl to code converter works

The converter reads your curl command the same way a Unix shell would, then pulls out the pieces of an HTTP request. There is no math here, just precise text parsing in two stages: tokenize, then interpret.

First it splits the command into tokens using real POSIX quoting rules. Single quotes are fully literal. Double quotes are literal except for the four backslash escapes \\, \", \$, and \`. A backslash outside quotes escapes the next character, and any unescaped space, tab, or newline ends a token. Adjacent quoted and unquoted runs join into one token, so pre"fix mid"post becomes the single token prefix midpost.

Then it interprets the tokens. The method is GET by default, -X/--request overrides it, and a body from -d/--data implies POST (an explicit -X always wins over that implication). Every -H/--header becomes a header, keyed by name. All -d values are joined with & to form the body. The URL is the value of --url, or the first bare argument that is not a flag. When there is a body but no Content-Type header, it defaults to curl’s own application/x-www-form-urlencoded.

Worked example

Take this command:

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

Tokenizing gives eight tokens: curl, -X, POST, -H, Content-Type: application/json, -d, {"name":"Ada"}, then the URL https://api.test/users. Note the single-quoted JSON stays one literal token even with its braces and colon.

Interpreting those tokens:

Field Result Why
Method POST Set by -X POST
URL https://api.test/users First bare argument
Header Content-Type: application/json From -H
Body {"name":"Ada"} From -d

Because an explicit Content-Type was given, the default urlencoded type is not added. If you removed the -H line, the converter would add content-type: application/x-www-form-urlencoded automatically, since a body was present.

How to use it

  • Paste a full command starting with curl. The leading program token can be curl, an absolute path ending in /curl, or curl.exe.
  • Use quotes the way you would in a terminal. Wrap JSON bodies and header values that contain spaces in quotes so they stay intact.
  • Add -X explicitly when you want a method that differs from what -d would imply, for example a PUT or DELETE that still carries a body.
  • Repeat -H for each header and repeat -d for each data field. Multiple -d flags are joined with &.

Limitations

This tool models the common request-shaping flags: -X, -H, the -d family, --url, and inline --flag=value syntax. Flags it does not recognize (for example -u, --cookie, -F multipart uploads, or @file body references) are skipped rather than expanded, so a command that relies on them will not round-trip perfectly. It also does not execute the request, follow redirects, or validate that the URL or headers are well formed. Treat the output as a faithful reading of your command’s syntax, not a guarantee that the server will accept it.

Frequently asked questions

Why does my -d body show up as a POST when I never wrote -X POST?

curl itself implies POST whenever you send data with -d or --data, so the converter does the same. If you actually want a GET or PUT with that body, add an explicit -X flag. An explicit method always wins over the implied POST.

Does the converter send the request or call the server?

No. It only parses the text of your command and shows you the structured request (method, URL, headers, body). Nothing is transmitted, and the values you paste never leave your browser.

What happens if I have two headers with the same name?

Headers are keyed by name, so a later header with the same name overwrites an earlier one. If you need both values, the converter keeps only the last occurrence. Content-Type detection ignores case, so 'content-type' and 'Content-Type' count as the same header.

Are single quotes and double quotes treated differently?

Yes, exactly as a POSIX shell treats them. Single quotes are fully literal with no escapes inside. Double quotes are literal except for the backslash escapes \\, \", \$, and \`. Whitespace inside either quote style stays part of the same token.

What if my command does not start with curl?

The converter expects the first token to be curl, /usr/bin/curl, or curl.exe. If it is something else, or if the command has no URL at all, you get an error instead of a guessed result.