cURL to Fetch, Axios & Python Converter
RFC 9110 HTTP SemanticsTransform Chrome DevTools & API documentation cURL commands into clean TypeScript/JavaScript Fetch, Axios, or Python Requests code.
1. Paste Raw cURL Command
const response = await fetch("https://api.openai.com/v1/chat/completions", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer sk-proj-example123"
},
body: JSON.stringify({
"model": "gpt-4o-mini",
"messages": [
{
"role": "user",
"content": "Hello!"
}
],
"temperature": 0.2
}),
});
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
const data = await response.json();
console.log(data);Multi-line backslash continuations (\), JSON --data-raw payloads, and Basic Auth (-u) flags are parsed automatically in your browser.
Translating Libcurl CLI Flags into Native HTTP Client Implementations
When debugging network requests via Chrome DevTools (Copy as cURL) or integrating REST/GraphQL APIs from developer documentation, commands are typically expressed as POSIX shell invocations of curl. Converting these flags accurately into application code requires handling implicit method promotion (when -d or --data-raw is present without an explicit -X flag, libcurl defaults to POST) and deserializing JSON bodies into native language dictionaries.
Fetch API Error Handling Caveats
Unlike Axios, the WHATWG fetch() API does not reject its Promise on HTTP 4xx or 5xx status codes; it only rejects on network-layer failures or DNS resolution errors. Production wrappers must explicitly inspect if (!response.ok) before parsing the response stream.
Python Requests json= vs data= Parameters
In Python's requests library, passing a native dictionary to the json= keyword argument automatically serializes the payload with json.dumps() and attaches Content-Type: application/json, whereas passing a dictionary to data= encodes it as application/x-www-form-urlencoded.