Designing a Write API
This chapter designs an API for a notes app, so that clients can create, change, and delete data, not only read it. It starts with the app and what its API must do. Then it makes the design decisions one at a time: the resource and its endpoints, the request that creates a note, the requests that replace or change one, and the request that deletes one. It ends with what a client should do when a request gets no response, and why some requests can be sent again without repeating their effect while others cannot.
After reading this chapter, you should be able to:
- Explain why a notes app needs an API and state its requirements
- Identify the resource and write its collection and item endpoints
- Name the HTTP methods for creating, reading, replacing, changing part of, and deleting a resource
- Write a request that creates a resource and read a
201 Createdresponse with itsLocationheader - Distinguish replacing a resource with
PUTfrom changing part of it withPATCH - Write a request that deletes a resource and explain
204 No Content - Explain why a timeout leaves the outcome of a write unknown
- Distinguish safe and idempotent requests, and say which methods are which
- Use an idempotency key so a
POSTcan be sent again without repeating its effect