Creating an HTTP service
We will create a schematic for our schematics library that scaffolds an Angular service. It will generate a service that imports the built-in HTTP client. It will also contain one method for each HTTP request involved in a CRUD operation.
The generation schematic we will build will not stand on its own. Instead, we will combine it with the existing generation schematic of the Angular CLI for services. Thus, we do not need a separate JSON schema.
Let’s get started by creating the schematic:
- Execute the following command to add a new schematic to our collection:
schematics blank crud-service
- Run the following command to install the
@schematics/angular
npm package:npm install @schematics/angular
- Open the
collection.json
file and modify thecrud-service
schematic:"crud-service": { "description": "Generate a CRUD HTTP service.", "factory"...