Scenario
The API docs prove the endpoint works with a curl one-liner, and now the frontend needs the same request as fetch or axios code. Rebuilding it by hand is where requests quietly diverge: the method gets dropped (fetch defaults to GET), the Content-Type header gets forgotten (so the body arrives as text), or shell quoting leaks into the JSON. Converting mechanically keeps the working request working.
Broken input
curl -X POST https://api.example.test/users -H 'Content-Type: application/json' -d '{"name":"Ada"}'
Goal
Use cURL to fetch / Axios to generate client code that preserves all four request ingredients — method, URL, headers, body — exactly as the known-good curl command sends them.
Tool sequence
- Open cURL to fetch / Axios.
- Paste the entire curl command, flags and quotes included —
-X POST,-H, and-deach map to a distinct part of the generated code. - Pick fetch or axios to match the codebase and read the output against the original: method POST, JSON content type, body
{"name":"Ada"}. - Note what the converter did with shell quoting — the single quotes around the JSON belong to the shell and correctly do not appear in the code.
- Format the snippet with Code Formatter before committing, and if the request later misbehaves, validate the body you are actually sending with JSON Validator.
Checkpoint output
fetch("https://api.example.test/users", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ name: "Ada" }),
});
Method, content type, and body all match the curl command — the client will send the same request the docs proved works.
Common mistakes
- Forgetting curl examples sometimes rely on implicit behavior —
-dalone implies POST, so a hand-port that drops-X POSTmay still work in curl and fail in fetch. - Copying the URL but losing the method, so the API answers
405 Method Not Allowed. - Treating shell quoting as part of the JSON payload and sending
'{"name":"Ada"}'with literal quotes. - Skipping the
Content-Typeheader, so the server parses the JSON body as form data or plain text.
Related tools and lessons
- URL Parser / Inspector - Inspect normalized URL parts and decoded query parameters.
- JSON Validator - Validate & pretty-print JSON.
- Code Formatter - Format CSS, JS & TypeScript with Prettier.
- Related lesson: Inspect a URL Before Debugging a Routing Bug
- Related lesson: Find the JSON Syntax Error Breaking a Request