Sending data — POST requests
GET fetches. POST creates. Learn to send data to a server.
⏱ Est. ~5 min
01 · Read
So far you've only used GET — asking a server for data. But you also need to send data: create users, submit forms, post comments.
That's what POST is for.
In curl: - -X POST sets the method to POST - -H "Content-Type: application/json" tells the server what format you're sending - -d '{...}' is the request body — the data you want to send
Key points
- GET = read. POST = create.
- -X POST switches the HTTP method
- -d '{...}' sends a JSON body
- Always add Content-Type: application/json when sending JSON
02 · Code example
Here's the structure of a POST request in curl.
POST with JSON body
curl -X POST https://api.example.com/todos \
-H "Content-Type: application/json" \
-d '{"text": "Learn curl", "done": false}'
Line by line: -X POST — use the POST method instead of GET -H "Content-Type: application/json" — tells the server the body is JSON -d '...' — the body data (use single quotes so the shell doesn't escape the double quotes inside)
03 · Terminal exercise
First, GET the current todo list to see what's in it.
(This section is interactive — please enable JavaScript.)
04 · Terminal exercise
Now POST a new todo to the server. Send it as a JSON body.
(This section is interactive — please enable JavaScript.)
05 · Fill in the blank
To specify an HTTP method in curl, use the _____ flag.
06 · Quiz
You want to add a new product to an e-commerce API. The API docs say POST /api/products. Which curl command is correct?
- curl https://shop.com/api/products?name=Shoes&price=50
- curl -X POST https://shop.com/api/products -H "Content-Type: application/json" -d '{"name":"Shoes","price":50}'
- curl -GET https://shop.com/api/products -d '{"name":"Shoes"}'
- curl --create https://shop.com/api/products -body '{"name":"Shoes"}'
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.