REST is an architectural approach for web services that uses HTTP methods to specify operations and URLs to select the data objects affected. It has no detailed specification, so implementations can differ while sharing these core ideas. section 23.2
Common method-and-URL combinations express operations on resource collections and individual objects:
- GET /products retrieves every object in the products collection. section 23.2
- GET /products/2 retrieves the object whose id is 2. section 23.2
- POST /products adds an object, with its JSON representation in the request body. section 23.2
- PUT /products/2 replaces one object, while PATCH /products/2 updates selected properties. section 23.2
- DELETE /products/2 removes the selected object. section 23.2
Selecting a product
A client sending GET to /products/2 asks the service for the product identified by 2. The server returns a JSON representation, such as the Lifejacket object in the example application. Angular can issue these requests asynchronously to obtain model data. section 23.2
A practical development service can expose collections such as products and orders through json-server. Middleware can inspect requests, require authentication for protected operations, and prevent ordinary users from modifying products or changing order status. section 5.1.2
Table 23.3. Common HTTP verbs and their effect in a RESTful web service
|
Verb
|
URL
|
Description
|
|
GET
|
/products
|
This combination retrieves all the objects in the
products collection.
|
|
GET
|
/products/2
|
This combination retrieves the object whose
id is
2 from the
products collection.
|
|
POST
|
/products
|
This combination is used to add a new object to the
products collection. The request body contains a JSON representation of the new object.
|
|
PUT
|
/products/2
|
This combination is used to replace the object in the
products collection whose
id is
2. The request body contains a JSON representation of the replacement object.
|
|
PATCH
|
/products/2
|
This combination is used to update a subset of the properties of the object in the
products collection whose
id is
2. The request body contains a JSON representation of the properties to update and the new values.
|
|
DELETE
|
/products/2
|
This combination is used to delete the product whose
id is
2 from the
products collection.
|
Use the method-and-URL table to compare collection retrieval, object retrieval, creation, replacement, partial updates, and deletion. section 23.2





















