induwara.lk
induwara.lkDeveloper · Utility

cURL to Code Converter

Paste any curl command and get the same HTTP request as ready-to-run code in JavaScript (fetch & axios), Python, Node.js, Go, and PHP. Everything is parsed in your browser — nothing is uploaded, no signup.

By Induwara AshinsanaUpdated Jun 30, 2026
Convert a curl commandto runnable code

Multi-line commands with trailing \ are supported. The leading $ prompt, if present, is stripped automatically.

Try a sample
MethodPOST
Headers2
BodyJSON
Output
JavaScript · fetch · request.js
const res = await fetch("https://api.example.com/messages", {
  method: "POST",
  headers: {
    "Authorization": "Bearer TOKEN123",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({"to":"94743252452","text":"hi"}),
});
const data = await res.json();
console.log(data);

Flag mappings follow the official curl man page. Basic auth (-u) is base64-encoded per RFC 7617. Sources are listed below the tool.

How it works

A curl command looks simple, but turning it into code by hand means remembering how each flag maps to your HTTP client. This converter does that mechanically. It runs a small shell-style tokenizer over the command — respecting single quotes, double quotes, backslash escapes, and \ line continuations — then classifies each token against the official curl flag definitions. There is no eval and no shell: the command is read as data, never executed.

The flag-to-code mapping follows the curl man page:

  • -X / --request sets the HTTP method (uppercased).
  • -H / --header becomes one header, split on the first colon so values with colons survive.
  • -d, --data, --data-raw and --data-binary set the body. With no -X, the presence of data makes the request a POST — curl's documented default.
  • -u user:pass becomes an Authorization: Basic header, base64-encoded per RFC 7617.
  • -F / --form becomes a multipart form; -b becomes a Cookie header; -G moves the data into the query string as a GET.

Bodies are normalized before emitting. When the request carries Content-Type: application/json and the body parses as JSON, the JavaScript targets use JSON.stringify and Python uses the json= keyword (which lets requests set the header itself). A -d body with no content type is emitted as a raw string and tagged application/x-www-form-urlencoded, matching what curl actually sends. Runtime-only flags such as -o, --proxy, and --insecurecan't be reproduced in code, so they are listed in a warning banner rather than silently dropped — the output is never quietly wrong. The three worked examples below are encoded as an in-code self-test (verifyWorkedExamples()) that runs on every build.

Worked examples

Example 1 — simple GET

Input

curl https://api.induwara.lk/v1/tools
  1. No -X flag and no body data.
  2. curl man page: with no method and no body, the default is GET.
  3. The single non-flag token is the URL.
  4. Result: GET https://api.induwara.lk/v1/tools, 0 headers, no body.

Output · JavaScript · fetch

const res = await fetch("https://api.induwara.lk/v1/tools");
const data = await res.json();

Example 2 — POST with JSON body and auth header

Input

curl -X POST https://api.example.com/messages \
  -H "Authorization: Bearer TOKEN123" \
  -H "Content-Type: application/json" \
  -d '{"to":"94743252452","text":"hi"}'
  1. -X POST sets the method explicitly.
  2. Each -H splits on the first colon into a header.
  3. Content-Type is application/json and the body parses as JSON.
  4. Python uses json= so requests sets the Content-Type itself.

Output · Python · requests

import requests

res = requests.post(
    "https://api.example.com/messages",
    headers={
      "Authorization": "Bearer TOKEN123",
    },
    json={
        "to": "94743252452",
        "text": "hi",
    },
)
print(res.json())

Example 3 — Basic auth shorthand (-u)

Input

curl -u admin:secret https://api.example.com/status
  1. -u admin:secret is HTTP Basic auth.
  2. Per RFC 7617, encode base64('admin:secret') = YWRtaW46c2VjcmV0.
  3. That becomes Authorization: Basic YWRtaW46c2VjcmV0.
  4. No body is present, so the method stays GET.

Output · JavaScript · fetch

const res = await fetch("https://api.example.com/status", {
  headers: {
    "Authorization": "Basic YWRtaW46c2VjcmV0",
  },
});
const data = await res.json();

Frequently asked questions

Sources & references

Related tools

Rate this tool
Be the first to rate

Comments & feedback

Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.

Found a curl flag that converts wrong, or want another target language?

Email me at [email protected] — most fixes ship within 24 hours.