From curl to code
Every curl command translates directly to real code
⏱ Est. ~8 min
01 · Read
Here's the secret: curl isn't just a testing tool. It's a translation guide.
Every curl command you write maps 1:1 to a JavaScript fetch call, a Python requests call, or any other HTTP client. Once a request works in curl, translating it to code is mechanical — Claude Code can do it in seconds.
This is every engineer's workflow:
1. Understand the API (read the docs) 2. Test the request with curl (confirm it works) 3. Translate to code (copy into the project) 4. Handle the response (parse and use the data)
Key points
- curl flags map directly to code: -H → headers object, -d → body
- Paste any working curl command into Claude Code: "translate this to JavaScript fetch"
- The translation is mechanical — the hard part is getting curl to work, not the code
- This workflow works in every language: JS, Python, Go, Ruby, and so on
02 · Code example
The same request written three ways: curl, JavaScript (fetch), and Python (requests).
curl
curl https://api.github.com/users/torvalds \
-H "Accept: application/json"
JavaScript (fetch)
const response = await fetch('https://api.github.com/users/torvalds', {
headers: {
'Accept': 'application/json'
}
});
const data = await response.json();
console.log(data.name); // 'Linus Torvalds'
Python (requests)
import requests
response = requests.get(
'https://api.github.com/users/torvalds',
headers={'Accept': 'application/json'}
)
data = response.json()
print(data['name']) # Linus Torvalds
Look at the mapping: - URL → first argument - -H "Key: Value" → headers object { 'Key': 'Value' } - -X POST → method: 'POST' - -d '{...}' → body: JSON.stringify({...}) The structure is the same. The syntax is different.
03 · Code example
A POST request — same data, three ways.
curl
curl -X POST https://api.example.com/posts \
-H "Content-Type: application/json" \
-H "Authorization: Bearer MY_TOKEN" \
-d '{"title": "Hello", "body": "World"}'
JavaScript (fetch)
const response = await fetch('https://api.example.com/posts', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer MY_TOKEN'
},
body: JSON.stringify({ title: 'Hello', body: 'World' })
});
const data = await response.json();
Python (requests)
import requests
response = requests.post(
'https://api.example.com/posts',
headers={
'Content-Type': 'application/json',
'Authorization': 'Bearer MY_TOKEN'
},
json={'title': 'Hello', 'body': 'World'}
)
data = response.json()
04 · Real-machine exercise
Write a curl command to fetch the 3 most recently updated public repos for microsoft on GitHub. Then ask Claude Code to translate it to JavaScript.
curl "https://api.github.com/users/microsoft/repos?sort=updated&per_page=3"
05 · Quiz
When translating to JavaScript fetch, which curl flag maps to the 'headers' object?
- -H (header)
- -d (data)
- -X (method)
- -o (output)
06 · Fill in the blank
The curl flag -d '{"name": "test"}' maps to the _____ property in a JavaScript fetch options object.
07 · Prompt template
Once your curl is working, use this prompt to ask Claude Code to translate it into code.
Translate this curl command into a JavaScript async function that returns the parsed JSON:
curl "https://api.github.com/users/microsoft/repos?sort=updated&per_page=3"
Name the function `getMicrosoftRepos` and handle errors properly.
08 · Quiz
In a JavaScript fetch call, which property replaces curl's -d flag?
09 · Fill in the blank
The curl flag -H "Key: Value" maps to the _____ object in a JavaScript fetch call.
Other lessons in this chapter
⚠ The full interactive experience needs JavaScript. Please enable it and reload.
※ This is an independent Traditional Chinese teaching project — not an official Anthropic product. Claude™ is a trademark of Anthropic, PBC.