curl to Code Converter

Convert a curl command to fetch, Node.js, Python, Go or PHP code, with axios, http.client or Guzzle as options — reads -X, -H, -d, -F and -u, and bash quoting.

Result: 10 lines, 246 characters

A curl command, rewritten in five languages

This tool parses a curl command and rewrites it as equivalent source code in the language you pick — a JavaScript fetch() call, a Node.js request using the built-in http/https module, a Python requests script, a Go net/http program, or a PHP cURL snippet. For Node.js, Python and PHP a Library select offers a second choice — axios, the standard library’s http.client, or Guzzle — each set up to behave as curl does, so an error status comes back as a response rather than an exception. It understands the flags you see most often in copied commands: -X/--request for the method, -H/--header for headers, -d/--data/--data-raw for the request body, and -u user:pass, which it turns into a Basic Authorization header — and also -F/--form multipart fields and file uploads, -T to PUT a file, and -d @file (or @- for standard input), which the generated code reads when it runs. Quoted arguments, bash $'...' quoting, backslash line-continuations and multi-line pastes are all handled, so you can paste a command exactly as the browser "Copy as cURL" feature produced it — on Windows, choose the bash (POSIX) version rather than the cmd one, whose ^ escapes are not read. A shell variable such as $TOKEN in the URL, a header or the body becomes the program’s own environment lookup — process.env, os.environ, os.Getenv or getenv — while a $(…) command is never run and is sent as written, and the pipes, redirects and other commands around the curl command are left out; the page names each one.

How to use it

Paste your curl command into the box, choose a target language, and the generated code appears instantly below — ready to copy or download. When no request body is present the method defaults to GET, a lone -d makes it POST, -I makes it HEAD, and -G moves the -d data into the query string, matching how curl behaves. Everything runs locally in your browser, so it is safe to convert commands that carry API tokens or credentials. This tool is the exact inverse of our curl command builder: build a command there, or paste one here to get working code.

Frequently asked questions

Which curl flags are supported?

The common ones in copied commands: -X/--request for the HTTP method, -H/--header for headers, -d/--data/--data-raw (and --data-binary) for the body, --url, -u user:pass which becomes a Basic Authorization header, -I/--head for HEAD, -G/--get to send -d data in the query string, and -b/--cookie name=value text as a Cookie header. -F/--form and --form-string build a multipart body, with name=@file as a file upload; -T uploads a file with PUT; and -d @file or @- reads the body from a file or standard input when the code runs. What cannot be carried together — -F beside -d, -T beside either — is said on the page rather than silently dropped. --compressed is accepted and ignored because fetch, requests and the others negotiate compression for you. Boolean flags such as -s, -L and -k are safely skipped.

What does the Node.js output use?

It uses the built-in Node http or https module, chosen from the URL scheme, so the generated snippet has zero npm dependencies. If your project uses axios, pick it from the Library select instead. Prefer fetch? Node 18+ ships a global fetch(), so the JavaScript (fetch) target also runs in modern Node.

Can I get axios, http.client or Guzzle instead?

Yes. For Node.js, Python and PHP a Library select appears beside the language: http / https or axios for Node.js, requests or http.client for Python, cURL or Guzzle for PHP. Each is written to behave as curl does — axios returns the body as text and does not throw on an error status, Guzzle’s http_errors is off, and http.client gets a UTF-8 body rather than its Latin-1 default. The choice rides in the page address as ?lib=, so a link opens the same code, and it goes back to the language’s own library when you change language.

Can it write the request as an .http file, HTTPie, Wget, JSON or HAR?

Yes. They sit under Other formats in the Target language menu, below the programming languages. HTTP (.http file) writes the request as the message VS Code’s REST Client and JetBrains run, with a body read from a file as < path. HTTPie and Wget write the same request for those clients, though Wget refuses a multipart form in a comment because it cannot send one. JSON (parsed request) shows the request as this tool read it, and HAR (request object) writes a HAR request object: the request alone, since a HAR entry also needs a response that a command that has not run cannot supply.