curl to typescript fetch converter
typetools
instant, client-side type converter • 0ms network latency
export interface RootPayloadResponse {
status: string;
data: unknown;
}
export async function fetchRootPayload(signal?: AbortSignal): Promise<RootPayloadResponse> {
const response = await fetch("https://api.typetools.dev/v1/compile", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer tok_live_98a7c2f1",
},
body: "{",
signal,
});
if (!response.ok) {
throw new Error(`HTTP Error ${response.status}: ${response.statusText}`);
}
return (await response.json()) as RootPayloadResponse;
}step-by-step integration guide
technical specification differences & end-to-end conversion workflow
Translating Shell-Escaped cURL Flags into Modern TypeScript Fetch AST
Developers routinely copy network requests from Chrome DevTools ("Copy as cURL") or Stripe/OpenAI API documentation containing dozens of shell flags: -X POST, -H 'Authorization: Bearer ...', --data-raw '{...}', -u user:pass, --compressed, and ANSI-C quoted strings ($'...'). Manually rewriting these shell commands into production TypeScript fetch() calls is tedious and prone to escaping errors—especially when converting Basic Auth credentials into Base64 headers, parsing URL query parameters into URLSearchParams, and typing both the outgoing JSON request payload and the expected response body.
POSIX Shell Tokenization, Header Normalization, and Payload Type Inference
Our client-side cURL-to-TypeScript converter implements a POSIX shell tokenizer inside a Web Worker that strips line-continuation backslashes (\) and unescapes single-quoted, double-quoted, and ANSI-C $'...' arguments. The engine extracts the HTTP method (inferring POST automatically when -d, --data, or --data-raw is present without an explicit -X flag), normalizes all -H / --header flags into a clean headers record, and converts -u flags into an Authorization: Basic header. Most importantly, if the request body is valid JSON, our AST engine parses the JSON payload, generates a dedicated TypeScript interface RequestPayload for the body, and emits a fully typed async function executeRequest<TResponse>() wrapper with HTTP status error handling.
frequently asked questions
common developer questions answered
q:Does the converter generate TypeScript interfaces for the JSON request body inside --data-raw?
Yes. Whenever a cURL command includes a JSON payload via -d, --data, or --data-raw, our AST parser extracts the JSON, generates a strongly typed RequestBody interface, and passes the typed object into JSON.stringify().
q:How are cURL commands copied from Chrome DevTools with $'...' ANSI-C quoting handled?
The built-in POSIX lexer unescapes ANSI-C $'...' strings, strips browser-internal pseudo-headers (like :authority or sec-ch-ua when optional), and preserves cookies and authorization headers cleanly.
q:Are my API keys or Bearer tokens inside the cURL command sent to any server?
Never. 100% of the cURL tokenization and TypeScript code generation runs locally inside your browser's Web Worker with zero network requests, keeping your Bearer tokens and cookies completely private.