What is the POST method?
The primary tool for sending data
While the GET method is for reading data, the POST method is for sending new data to the server.
Imagine filling out a driver's license application and handing it to the clerk at the DMV. You aren't just asking for information; you are submitting a new record that will be created and saved. In the web development world, when a browser creates a new user account, saves a blog post, or registers a payment, it uses a POST request.
Changing the server's state
Unlike GET requests, POST requests are not safe. This means that they intentionally change the state of the server. They create records in a database, send emails, or trigger financial transactions.
Because they change things, your browser treats POST requests more carefully. You can't just type a URL in your address bar and press Enter to make a POST request: the browser will always send a GET request when you do that.
The concept of non-idempotency
POST requests are not idempotent. This means that if you make the exact same request twice, the state of the server will change twice.
If you click "Submit Order" on a shopping cart and send a POST request, the server creates the order. If you accidentally refresh the page or click the same button again, a second POST request is sent, and the server will create a second identical order. This is why browsers usually ask you to confirm before refreshing a page that was the result of a form submission.
Summary
| Concept | Key Point |
|---|---|
| Purpose | Send data to the server, usually to create a new resource |
| Not Safe | Modifies data and changes the server's state |
| Not Idempotent | Repeating the request has a different effect (it creates multiple records) |
| Usage | Mostly HTML forms with method="POST" and API calls |
Keep going with lesson 2
Anatomy of a POST request
A POST request carries data in its body, and the Content-Type header tells the server its format.
A free account also gives you the quizzes, your progress and notes, and the discussion.