liveBook · Manning

REST

As explained in Pro Angular 16

REST is an architectural approach for designing web services around resources, URLs, and HTTP operations.

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

How Pro Angular 16 covers it

How deep it goes
Defines resource selection and HTTP operations, demonstrates standard combinations, and cautions that implementations vary without specifying a formal standard.
Examples
Uses products and orders collections, the /products/2 endpoint, JSON responses, and json-server middleware.
What it assumes
Assumes familiarity with HTTP methods, URLs, JSON, and client requests while establishing their roles in RESTful services.
What you can do after
Apply via HTTP requests by selecting resource URLs, choosing verbs, and supplying JSON request bodies where required.
How it connects
Connects HTTP methods, URLs, JSON, web services, asynchronous requests, authentication, and authorization.

Also explained in

Compare how 22 books explain REST →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pro Angular 16. The section links point to the parts of the book it draws on.