cURL to TypeScript Converter
Convert curl commands to TypeScript code using fetch. Paste a command and the TypeScript snippet appears instantly — everything runs in your browser.
- Instant ConversionCode updates as you type
- Multiple Languages40 languages, 61 libraries
- 100% Client SideYour data stays private
How to use this tool
Steps for using the cURL to Code.
- Copy a curl command — from API documentation, or from your browser's DevTools (Network tab → right-click a request → Copy as cURL (bash)).
- Paste it into Enter cURL command. The TypeScript fetch code appears instantly.
- Set up: Nothing to install for fetch. For Node.js, add
@types/nodeso TypeScript knows Node's APIs (npm install -D @types/node). - Run it: Save the code as
request.tsand runnpx tsx request.ts, ornode request.tson Node.js 23.6 and later. Deno and Bun run it directly. Replace placeholders such asYOUR_TOKENfirst, and check any notes under the editors for curl options that have no fetch equivalent.
Example
GET with headers → TypeScript fetch
curl 'https://api.example.com/v1/users?page=2' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer YOUR_TOKEN'export {};
const headers: Record<string, string> = {
'Accept': 'application/json',
'Authorization': 'Bearer YOUR_TOKEN',
};
const init: RequestInit = {
headers,
};
const response: Response = await fetch('https://api.example.com/v1/users?page=2', init);
const data: unknown = await response.json();
console.log(response.status, data);Common use cases
- TypeScript backends and scripts
- Typed API clients in Next.js, NestJS or Express
Converting curl to TypeScript fetch
The TypeScript code uses fetch, built into Node.js 18+, Deno, Bun and browsers, with explicit types: Record<string, string> headers, a typed RequestInit and Response.
The converter reads the curl command the way curl does — the method (-X), headers (-H), request bodies (-d, --data-raw, --json, -F), query strings, basic auth (-u) and cookies — and writes the equivalent fetch code. Options that have no fetch equivalent are listed under the editors rather than silently dropped.
Limitations
- The code is a starting point: add timeouts, retries and error handling for production use.
- Secrets in the curl command are copied into the code — move them to environment variables before committing.
Frequently asked questions
Why is the response typed as unknown?
TypeScript can't know the shape of an API response. Define an interface for it and check the data (with a library such as zod) before using it.
Why export {} at the top?
It makes the file a module, which TypeScript requires for top-level await. Files that import something are modules already.
Does this work in the browser?
Yes, except reading local files for uploads, which needs Node.js. In a browser, the API must allow your site through CORS; requests that work with curl can be blocked by the browser otherwise.
Is my curl command sent to a server?
No. The conversion runs entirely in your browser, so tokens and passwords in the command never leave your device. Still, replace real secrets before sharing the generated code.