liveBook · Manning

Web service

As explained in Pro Angular 16

A web service is a network-accessible software service that provides data or operations to clients through web protocols.

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

How Pro Angular 16 covers it

How deep it goes
Defines REST around HTTP verbs and URLs, compares common operations, and cautions that implementations vary.
Examples
Uses products and orders, a Kayak response, localhost URLs, json-server, and an HTTP verb table.
What you can do after
Operate/configure json-server, test product endpoints, and choose HTTP methods for collection and object operations.
How it connects
Connects REST, HTTP methods, URLs, JSON, Angular HttpClient, observables, CORS, authentication, and authorization.

Also explained in

Compare how 6 books explain web service →

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.