An HTTP method, also called a verb, tells a RESTful web service which operation to perform. The request URL identifies the collection or object affected, so the method and URL work together to express the request. section 23.2
Common method-and-URL combinations include:
- GET /products retrieves every object in the products collection. section 23.2
- GET /products/2 retrieves the object whose identifier is 2. section 23.2
- POST /products adds a new object, supplied as JSON in the request body. section 23.2
- PUT /products/2 replaces the selected object, while PATCH /products/2 updates only selected properties. section 23.2
- DELETE /products/2 removes the selected object. section 23.2
Selecting a product
A browser request to http://localhost:3500/products/2 uses GET by default. The URL selects the products collection item with identifier 2, and the server returns its JSON representation, such as the Lifejacket product. section 23.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 retrieval, creation, replacement, partial updates, and deletion. section 23.2









