Skip to content
Utilerio

cURL to Code

Turn a cURL command into JavaScript Fetch, C# HttpClient or Python Requests code.

Generated code

fetch("https://api.example.com/users", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Authorization": "Bearer YOUR_TOKEN"
  },
  body: JSON.stringify({"name":"Ada Lovelace"})
})
  .then((response) => response.json())
  .then((data) => console.log(data))
  .catch((error) => console.error(error));

Was this tool useful?

About this tool

A cURL command copied from browser dev tools or an API's documentation is the fastest way to describe an HTTP request — but it's shell syntax, not the language you're actually writing in. Translating it by hand means re-typing the method, every header and the body, and it's easy to drop something.

How to use it

  1. Paste a cURL command — multi-line with backslash continuations works the same as a single line.
  2. Pick a target: JavaScript (Fetch), C# (HttpClient) or Python (Requests).
  3. The generated code carries over the method, URL, headers, query parameters, request body and basic auth.

Examples

A JSON POST request

curl -X POST https://api.example.com/users -H "Content-Type: application/json" -d '{"name":"Ada"}'
fetch("https://api.example.com/users", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({"name":"Ada"})
})

Common problems

The parser didn't recognise one of my cURL flags.
The common flags (-X, -H, -d and its variants, -u, -G, -A, -b) are handled explicitly; an unrecognised flag is skipped rather than guessed at, so double-check the generated code against flags outside that list.
My command uses -G to send data as query parameters instead of a body.
This is supported — with -G, whatever was passed to -d is appended to the URL as a query string instead of becoming the request body.

Frequently asked questions