DevTools Logo

cURL to Code Converter

cURL to Code Converter

Convert cURL commands to code in multiple languages

cURL Command

Paste your cURL command below

Examples

Convert a form-encoded POST with multiple headers

Input
curl -X POST https://httpbin.org/post \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -H 'Accept: application/json' \
  -d 'name=John&email=john@example.com'
Output
fetch('https://httpbin.org/post', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded',
    'Accept': 'application/json',
  },
  body: 'name=John&email=john@example.com',
});

Method is read from `-X POST`, two headers are split on the first colon, and the `-d` body is detected as non-JSON (no leading `{` or `[`) so it is emitted as a raw string. The same parsed structure produces a `requests.post(...)`, a `curl_setopt(...)` block and a Go `http.NewRequest(...)` call in the other tabs.

Convert a simple authenticated GET

Input
curl https://api.github.com/user \
  -H 'Authorization: Bearer ghp_1234567890'
Output
fetch('https://api.github.com/user', {
  method: 'GET',
  headers: {
    'Authorization': 'Bearer ghp_1234567890',
  },
});

No `-X` is present, so the method defaults to `GET` and the body is omitted. The Python tab emits `requests.get(...)` with the same Authorization header; the Go tab uses `http.NewRequest('GET', url, nil)` plus `req.Header.Set(...)`.

Convert a bare DELETE without a body

Input
curl -X DELETE https://api.example.com/users/42
Output
fetch('https://api.example.com/users/42', {
  method: 'DELETE',
});

With no `-H` and no `-d`, the generated code is a one-line method override. The Go tab uses `http.NewRequest('DELETE', url, nil)`; the PHP tab sets `CURLOPT_CUSTOMREQUEST, 'DELETE'` and omits the headers and postfields blocks entirely.

About this tool

The cURL to Code Converter parses a cURL command and produces an equivalent request in JavaScript (fetch), Python (requests), PHP (cURL extension) and Go (net/http). Paste the cURL you copied from API docs, browser dev tools, or your terminal history, pick a target language, and copy the generated code straight into your project.

The parser extracts the URL, HTTP method (from `-X`), every `-H` header (split on the first colon), and the body (from `-d` or `--data-binary`). It then formats the result in the chosen language: a `fetch(...)` call for JavaScript, a `requests.<method>(...)` for Python, a `curl_setopt(...)` sequence for PHP, or a `http.NewRequest` + `client.Do` pair for Go. For `-d` payloads, the parser tries `JSON.parse`; if it succeeds the body is wrapped in `JSON.stringify(...)` / `json=...`, otherwise it is emitted as a raw string.

The tool is a pure formatter — no request is sent. The cURL you paste is parsed in your browser, the code is generated locally, and the network is never touched, so it's safe to convert commands that point at internal or authenticated endpoints.

How to use

  1. Paste your cURL command

    Copy a cURL from API docs, terminal history or browser dev tools and paste it into the cURL Command textarea. The tool parses it on every keystroke.

  2. Read the parsed summary

    The Method and URL appear immediately under the input. The Parsed Details card below shows every header and the body in a clean key/value layout.

  3. Pick a target language

    Click the JavaScript, Python, PHP or Go tab to switch the generated code. The output updates instantly with the same parsed data in a different shape.

  4. Copy the snippet

    Hit Copy in the top-right of the Generated Code card to copy the snippet to your clipboard, ready to drop into a script or test file.

Use cases

Turning API docs into a quick test script

API reference pages often include a cURL you can copy and paste — the converter turns it into a fetch / requests / net/http snippet that you can drop into a unit test or a REPL.

Migrating a shell script to a real HTTP client

A cron job that hits an endpoint with cURL is fragile: no timeout, no retries, no error handling. Paste the cURL, switch to Python or Go, and you have a baseline you can extend with proper timeouts and structured error handling.

Sharing a working call with a teammate in a different language

Front-end, back-end and integration engineers often live in different runtimes. Paste a cURL once, switch the language tab, and copy the version each teammate needs.

Bootstrapping a client library for a new API

When you onboard against a new third-party API, paste 5-10 cURL commands covering the main endpoints and you have a working first draft of the client in your target language — ready to refactor into a proper class.

What the parser extracts

cURL flagParsed into
(URL after curl)Endpoint / request target
-X <METHOD>HTTP method (GET default)
-H 'Key: Value'One entry per header in the headers object
-d '<body>'Request body (stringified if JSON, raw otherwise)
--data-binary '<body>'Same as -d

The data regex is intentionally simple: a balanced-quote body. Form-encoded bodies and unquoted JSON bodies parse correctly; bodies containing the same quote type as the outer wrapper stop at the first inner quote.

Common mistakes

Mistake:Pasting a cURL whose body contains the same quote character as the outer wrapper.

Fix:The parser's body regex is intentionally simple: it captures up to the next matching quote. A JSON body like `-d '{"x":1}'` will be captured only as `{` because the inner `"` are not the wrapping quote. Switch the wrapper to double quotes or pre-encode the body to a single line.

Mistake:Forgetting to include `-X POST` and assuming the method will be detected from `-d`.

Fix:cURL itself only sends POST when `-d` is present, but this converter only reads `-X`. A `-d` payload with no `-X` is parsed as a GET request and the body is silently dropped — add `-X POST` to be explicit.

Mistake:Treating the generated code as a complete, production-ready client.

Fix:The output is a minimal starting point: no timeouts, no retry/backoff, no authentication refresh, no error handling. Wrap it in your project's standard HTTP-client patterns (timeouts, status checks, JSON parsing, structured errors) before shipping.

Mistake:Expecting Go output to handle a `*http.Response` body that must be closed.

Fix:The Go template does include `defer resp.Body.Close()` and `io.ReadAll(resp.Body)`, but it ignores the HTTP error and the status code. A real client must check `err` and `resp.StatusCode` before consuming the body.

Frequently asked questions

References & standards