REST API consumption
One of the main uses of Angular services is undoubtedly communication with the backend of the application, using the Representational State Transfer (REST) protocol.
Let’s learn about this feature in practice by preparing our project to consume its backend.
First, let’s upload the backend locally by accessing the gym-diary-backend
folder and using the following command in your command-line prompt:
npm start
We can leave this command running and can now create the services for the consumption of the API.
To carry out this consumption, Angular has a specialized service – HttpClient
. To use it, we will first import its module into the app.module.ts
file:
import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { AppRoutingModule } from './app-routing.module'; import { HttpClientModule } from '@angular/common/http'; import { AppComponent...