In this lesson, you went down the endpoint table for the repair café’s ticket API and found out which of its requests a client can safely send again after a timeout.
Key Points
- A timeout leaves the client unsure. Dev’s desk runs on the library hall’s Wi-Fi. When a request times out, the request may have been lost on its way in, and nothing happened. Or the server did the work, and its answer was lost on the way back. From the desk, both look the same.
- A resent
POSTcreates another ticket. Restart your app so it starts from the five tickets intickets.json, then send Rosa’s radio twice. Both answers are201 Created, each with a different id. When you list the tickets, Rosa’s name turns up twice, so there are seven, because everyPOSTto the collection creates a new ticket. - A resent
DELETEchanges nothing more. Your app can’t answer a ticket’s own path yet, so this follows what your table promises. After the copy of Rosa’s radio is deleted, a secondDELETEto its path answers404 Not Found, because the copy is already gone. The list still holds six tickets, with one Rosa’s radio. The answer is different, but the tickets end up as they did after the first one. - A request is idempotent when sending it twice leaves the server as sending it once does. The answer can change, as the
404did. The definition looks only at the state the tickets end up in. - A safe method like
GETasks for no change, so it’s idempotent too.DELETEis idempotent, andPOSTto the collection isn’t. HTTP promises this forGET,PUTandDELETE, among others. - HTTP doesn’t promise that a
PATCHis idempotent. Your table’sPATCHsets the status to a value, so putting Priya’s toaster on the bench twice leaves it on the bench either way. If a volunteer changes the ticket in between, a latePATCHundoes their change. That happens even to aPATCHsent only once, so it’s a separate problem from resending. - A request that asks for a step can’t be resent safely. Say another API had
POST /tickets/5/next-status. If the answer is lost and the desk resends, Aiko’s bike is marked fixed while it’s still on the bench. UsingPOSTbreaks no HTTP rule. The trouble is that the request asks for a step, and as aPATCHit would be as unsafe. After a timeout, a client can’t safely resend it without knowing whether the first one landed. YourPATCHnames the status, so the desk can resend it. - A timed-out
POSTisn’t resent automatically. Resending Rosa’s radio could make a copy. Dev can list the tickets and look for the radio, but a missing radio doesn’t prove the first request failed, since the server may still be saving it. Making aPOSTsafe to resend needs the server’s help, which is beyond this course. - Two names you may meet. Many GraphQL APIs send requests as a
POSTto one path, so the method can’t say what’s safe to repeat. HATEOAS, one of REST’s own rules, has answers link to the next requests.
Here’s the endpoint table with the question this lesson asked of each row:
| Method | Path | Success | Twice = once? |
|---|---|---|---|
| GET | /tickets |
200 | Yes |
| POST | /tickets |
201, Location | No |
| GET | /tickets/:id |
200 | Yes |
| PATCH | /tickets/:id |
200 | Yes, it sets a value |
| DELETE | /tickets/:id |
204 | Yes |