HTTP Verbs
- Use HTTP methods appropriately for the operation you are performing. CRUD (Create, Read, Update, Delete) operations and the correct response for each are as follows:
- GET lists Resources in a Collection, or a single Resource, returning a 200 status and the requested Resource(s)
- POST creates a new Resource in a Collection, returning a 201 status and the new Resource if it is available. For a Resource that is not synchronously created, a 202 status and as much information as is currently available should be returned; usually there will be a callback to deliver the Resource once it is available.
- PUT replaces a complete Resource with the supplied representation, returning a 200 status and the updated Resource
- PATCH partially updates a Resource with the supplied fields, returning a 200 status and the updated Resource
- DELETE removes a Resource, returning a 204 status status and no body
Examples
GET members/
- lists all the resources of the collection membersGET members/bob
- lists the details of bob who is a resources of the collection membersPOST members -d '{"name": "Harry", "age": 22, "phone_number": "14155550100"}'
- create a new member called HarryPUT members/harry -d '{"name": "Harry", "age": 23, "phone_number": "14155550100"}'
- replace all of Harry’s detailsPATCH members/harry -d '{"age": 23}'
- update Harry’s age onlyDELETE members/steve
- remove the member Steve from the collection
Why did we choose this?
Pre-existing standard
Related Links
- The Method Definitions in the RFC2616 HTTP 1.1 spec are relevant to this part of API design.
- For the not-so-happy path, there are error format guidelines to guide you.
- All responses should follow HAL-JSON format.