Skip to content
YAS.SH
Developer🔒 Browser (client-side)API available📴 Works offlineintermediate

cURL to Fetch Converter

Translates cURL CLI commands into clean, idiomatic JavaScript/TypeScript fetch, Python requests, and Go http code.

Data stays in your browser
Ready to runInstant execution
All tools →
Result

What does this tool do?

Translates cURL CLI commands into clean, idiomatic JavaScript/TypeScript fetch, Python requests, and Go http code.

Why would I use it?

  • You captured a cURL command from Chrome DevTools or API documentation and need to implement it in code.
  • You want to avoid syntax errors when formatting JSON payloads, headers, or query parameters in backend code.
  • You are converting legacy shell scripts into modern microservices.

Real-life example

Input
curl -X POST https://api.example.com/v1/users -H 'Content-Type: application/json' -d '{"name":"Alice"}'
Output
const res = await fetch('https://api.example.com/v1/users', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name: 'Alice' }) });

Extracts headers, method, URL, and parses JSON body automatically.

Input → Process → Output → Next

Input
Paste any valid cURL command.
Process
Parses flags (-X, -H, -d, --data-raw, -u) and constructs typed code snippets.
Output
Ready-to-copy code in TypeScript Fetch, Python Requests, and Go HTTP.
Next action
Paste the snippet into your project or API client.

Common mistakes

  • Leaving sensitive API keys or Bearer tokens in client-side browser code.
  • Forgetting to handle async/await or promise rejections in production code.
  • Not setting proper Content-Type headers when sending JSON payloads.

What the result means

A direct translation of shell cURL parameters into target programming language HTTP clients.

Privacy & security

Your input is processed entirely in your browser and never sent to a YAS server.

API

Endpoint
POST https://yas.sh/api/v1/tools/curl-to-fetch
Request Header
Content-Type: application/json
cURL
curl -X POST "https://yas.sh/api/v1/tools/curl-to-fetch" \
  -H "Content-Type: application/json" \
  -d '{"input":"curl -X POST https://api.example.com -d '{\"a\":1}'"}'
JavaScript
const res = await fetch("https://yas.sh/api/v1/tools/curl-to-fetch", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
  "input": "curl -X POST https://api.example.com -d '{\"a\":1}'"
}),
});
const data = await res.json();
Python
import requests

r = requests.post("https://yas.sh/api/v1/tools/curl-to-fetch", json={"input":"curl -X POST https://api.example.com -d '{\"a\":1}'"})
data = r.json()
FieldTypeRequiredDescription
inputstringYescURL command
Success response
{ "slug": "curl-to-fetch", "parsed": { "url": "https://api.example.com", "method": "POST" } }

Convert cURL command to JS Fetch, Python, and Go code.

Error responses
  • 400 VALIDATION_ERROR — invalid input or unsupported option.
  • 413 PAYLOAD_TOO_LARGE — input exceeds the 64 KB limit.
  • 429 RATE_LIMIT_EXCEEDED — rate limit exceeded (60 req/min).
Limits
  • Maximum input: 64 KB per request.
  • Rate limit: 60 requests/min per IP address.
  • Authenticated accounts benefit from higher tier quotas.

cURL to Fetch Converter: technical reference, use cases and FAQ

How cURL to Fetch Converter works

The converter tokenises the cURL command with shell-aware splitting — respecting single quotes, double quotes and backslash line continuations — then maps each recognised flag onto the target language's HTTP client. -X sets the method, -H adds a header, -d / --data supplies a body, -u produces a Basic Authorization header, and --compressed maps to an Accept-Encoding header that the client library usually handles itself.

Several cURL behaviours are implicit and must be reconstructed. Passing -d without -X implies POST and, unless a Content-Type header is present, implies application/x-www-form-urlencoded — not JSON. Reproducing that faithfully matters, because a request that works in the terminal and fails from code usually differs on exactly this header.

Redirect and cookie semantics also differ by target. cURL does not follow redirects unless -L is given, while fetch() follows them by default; cURL sends no cookies unless -b or -c is used, while fetch() sends them only when credentials is set to 'include' or 'same-origin'. The generated code makes these choices explicit rather than inheriting a default that changes behaviour.

When to use it: real-world scenarios

Turning a browser 'Copy as cURL' into application code

DevTools produces a working cURL command including every header the browser sent. Converting it gives a runnable fetch() call, after which you delete the headers you do not need — most of the sec-* and user-agent set can go.

Porting a vendor's documented example

API documentation is written in cURL. Converting to Python requests or Go removes the transcription errors that occur when hand-copying a long header block or a nested JSON body.

Reproducing a failing request from a support ticket

A customer pastes the cURL command that fails. Converting it into your stack lets you run it inside the same client, interceptors and TLS configuration your application actually uses.

Writing an integration test from a manual request

Once a request works in the terminal, the converted code becomes the body of a test case, which pins the exact headers and payload that the endpoint was verified against.

Pro tips

  • Strip credentials before converting or sharing. Copy-as-cURL includes Authorization headers and session cookies verbatim, and those routinely leak into tickets and commit history.
  • Add Content-Type: application/json explicitly when the body is JSON. cURL will not add it for you, and many frameworks reject or mis-parse the body without it.
  • In browsers, fetch() cannot set forbidden headers such as Host, Referer, Cookie or Origin. If the original request depended on them, the converted call must run server-side.
  • Requests that succeed from cURL but fail from a browser are usually blocked by CORS, not by your code — cURL has no same-origin policy.

Limitations and edge cases

What this tool deliberately does not do, and where it will disagree with other implementations.

  • Exotic cURL flags (--form-string with typed parts, --cert, --resolve, --interface, proxy options) have no direct equivalent and are not translated.
  • Multipart uploads with @file references cannot be reproduced verbatim in browser JavaScript, which needs a File object from an input element or a Blob.
  • Shell interpolation is not evaluated. $TOKEN and $(cat key.pem) are copied as text, because the converter does not execute the shell.
  • Generated code targets the common case and should be reviewed for retry, timeout and error handling, none of which cURL expresses.

Frequently asked questions

Why does my converted request fail with CORS when cURL worked?
cURL is not a browser and ignores the same-origin policy. Browser fetch() requires the server to return the appropriate Access-Control-Allow-Origin headers, and preflights any request with custom headers or a non-simple method.
Does -d always mean POST?
Yes, unless -X specifies another method. cURL also defaults the content type to application/x-www-form-urlencoded, so JSON bodies need an explicit Content-Type header.
Is my cURL command sent to a server for conversion?
No. Parsing and code generation run in your browser. Even so, remove tokens before pasting anything anywhere — the habit matters more than any single tool's guarantees.
Which output languages are supported?
JavaScript fetch(), Python requests and Go net/http. All three preserve method, headers, body and authentication; adjust timeout and TLS settings to your environment afterwards.
Ask YAS AI
🍪 Cookies & privacy. Essential cookies keep you signed in and remember language and theme. Google AdSense and reCAPTCHA are Google technologies: AdSense runs only after Accept All; reCAPTCHA loads on sign-in and contact forms. See how Google uses data: https://policies.google.com/technologies/partner-sites cookie policy · privacy policy.
Settings