REST
easy 26 minREST is a style for network APIs: everything worth naming gets an address, and a small shared set of HTTP methods acts on it.
When it comes up
The moments this idea belongs in a design interview, and the moments it does not.
Signals
When it comes up
| You hear | Say | Because |
|---|---|---|
| Public API, many partners | REST with OpenAPI | Everyone can call it |
| Read heavy, same data for all | GET with Cache-Control | The CDN answers most of it |
| Two people edit one thing | ETag and If-Match | No silent overwrite |
| Payments over mobile | POST with an idempotency key | A repeat must not charge twice |
| Chat or live positions | Not plain REST | The server must push |
| Every screen differs | Consider GraphQL | Fixed shapes fit badly |
Choices
Explain your choices
How should the client change the end time of a booking?
BreaksGET /updateBooking with parameters
- How
- A link that writes.
- Limit
- GET is safe by contract. Prefetching, crawlers and retries would change bookings.
- Choose when
- Never.
WorksPUT the whole booking
- How
- Send every field.
- Limit
- An older client drops fields that it does not know, and a second editor's change is lost.
- Choose when
- Small resources owned by one client.
StrongPATCH with If-Match
- How
- Merge patch with the new end time and the ETag. 412 if the version moved on, 422 if the seat is taken.
- Limit
- Clients must handle 412.
- Choose when
- Shared resources that several clients edit.
Can I retry this?