Creating an HTTP service
For our schematics library, we will create a schematic 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 that is involved in a CRUD operation.
The generation schematic that we are going to 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
- Open the
collection.json
file and provide an explanatory description for the schematic:"crud-service": { Â Â "description": "Generate a CRUD HTTP service", Â Â "factory": "./crud-service/index#crudService" }
- Create a folder named
files
inside thecrud-service
...