A web service provides application data or operations over HTTP. In a RESTful design, the HTTP method selects the operation and the URL selects the collection or object affected. section 23.2
Common RESTful combinations include:
- GET /products retrieves a collection; GET /products/2 retrieves the object whose id is 2. section 23.2
- POST /products adds an object, PUT /products/2 replaces one, PATCH /products/2 updates selected properties, and DELETE /products/2 removes one. section 23.2
- Implementations vary: confirm the accepted verbs, URL format, request body, and server-side requirements before integrating a service. section 23.2
SportsStore development service
A json-server instance exposes products and orders from data.js. Running npm run json starts it on port 3500, and requesting http://localhost:3500/products/1 returns the Kayak product as JSON. Middleware protects selected order and product operations with authentication rules. section 5.1.2 section 5.1.6
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 HTTP verb table to compare collection and object URLs with their corresponding RESTful operations. section 23.2





