TAKE A BREAK

So, what is a REST API? A REST API is an interface that lets one program request data or trigger actions in another program over HTTP, the same protocol your browser uses to load web pages. It exposes resources at URLs and lets clients act on them with a small set of standard verbs: GET, POST, PUT, and DELETE. Learn those four and you can read most API documentation.
REST stands for Representational State Transfer. The term comes from Roy Fielding's 2000 doctoral dissertation at UC Irvine, where he described an architectural style for networked systems. The Chapter 5 text of the dissertation lays out those constraints. An API that follows them is called a REST API, or "RESTful."
REST is not a protocol you install or a file format you parse. Red Hat makes this point in its explainer on REST APIs. It is a set of design rules. IBM lists six of them in its overview of REST APIs, including a uniform interface, which means resources are reached in a consistent way.
Here is the one thing to remember: every REST API is an API, but not every API is REST.
Think about ordering dinner. You don't walk into the kitchen and start cooking. You read the menu, tell the waiter what you want, and the waiter brings back a dish. A REST API works the same way:
For the verbs below, we'll use one imaginary bistro booking system. Each reservation lives at its own address, such as /reservations/42, and the verb tells the waiter what to do with it. The domain bistro.example is a placeholder.
GET asks for information. It's like asking the waiter, "What time is my booking?"
Request: GET /reservations/42 with no body.
The server answers with 200 OK and the current data, for example {"id": 42, "name": "Ana", "party_size": 2, "time": "19:30"}.
GET should only read. Calling it ten times should not change anything on the server.
POST adds something new. It's like placing a brand-new booking.
Request: POST /reservations with the body {"name": "Ana", "party_size": 2, "time": "19:30"}.
A good response is 201 Created, with a Location header pointing to the new record, such as /reservations/43. Notice that the server chose the new ID. The HTTP methods guide from REST API Tutorial recommends this 201 Created pattern for POST.
PUT updates an existing item by sending its complete new state. It's like telling the waiter, "Change booking 42 to four people at 8:00 PM," but with the full booking details, not just the changes.
Request: PUT /reservations/42 with the body {"name": "Ana", "party_size": 4, "time": "20:00"}.
The usual success response is 200 OK. If you leave out a field, many APIs will treat it as missing, so send the full record. Some APIs also let PUT create a resource at that exact address when none exists. Check the documentation for the API you're using.
DELETE cancels the booking.
Request: DELETE /reservations/42 with no body.
A typical success response is 204 No Content, meaning the request worked and there is nothing to send back. If you send the same DELETE again, the reservation is still gone, and the server usually answers with 404 Not Found.
A method is idempotent if sending it twice has the same effect as sending it once. Moesif's guide to API methods lists GET, PUT, and DELETE as idempotent and POST as not. That's why retrying a PUT after a network glitch is safe, while retrying a POST can create two bookings.
| Verb | What it does | Typical success response | Idempotent? |
|---|---|---|---|
| GET | Reads a resource | 200 OK | Yes |
| POST | Creates a resource | 201 Created | No |
| PUT | Replaces a resource | 200 OK or 204 No Content | Yes |
| DELETE | Removes a resource | 204 No Content | Yes |
These two confuse almost everyone. The question to ask is: who chooses the address of the new thing?
With POST, you send data to a collection such as /reservations, and the server decides the new ID and URL. With PUT, you name the exact address, such as /reservations/42, and send the complete state for that item. If you already know the ID, PUT is the natural choice. If the server should assign it, use POST.
A simple rule of thumb: POST to the collection to create, and PUT to a specific item to replace it.
The analogy works well until you ask what the waiter remembers. A human waiter recalls that you like the window table and that you're allergic to nuts. A REST API is stateless, which means the server does not keep track of your previous requests between calls. Every request has to carry everything the server needs: an authentication token, the resource ID, and the data to change.
In practice, you send your API key with every request, not once at the start of a session. Stateless design keeps servers simpler to run and scale, and it is one reason REST fits the web so well.
GET /reservations/42, not /getReservation?id=42. The method already says the action, so URLs should name resources./reservations?party_size=2.No. "API" is the broad category. A REST API is one style of API that follows REST constraints and usually runs over HTTP.
No. REST is a set of design constraints. It relies on HTTP, which is the protocol that carries the requests and responses.
Representational State Transfer. The name matters less than the idea behind it: resources at URLs, accessed through standard methods.
POST creates a new item in a collection and lets the server assign its address. PUT replaces an item at an address you specify. When in doubt, check the API documentation.
A REST API lets programs talk to each other through standard HTTP requests. Remember the four verbs: GET reads, POST creates, PUT replaces, and DELETE removes. Keep URLs focused on nouns, check status codes, and remember that the server won't remember you between requests. With those basics, the next API documentation you open will be much easier to read.