JSON communication
From a web browser, you could use an XMLHttpRequest
object to make HTTP calls, but this is cumbersome to use and considered low-level API. Angular's HttpClientModule
provides an HttpClient
class that we can import and use for invoking the REST endpoints. This is a convenient class that provides methods equivalent to HTTP methods found for the web such as GET, POST, PUT, DELETE, and more. The methods provided are not only simpler to work with but also provide strong typing support. To use this class, we first import it into the Service
classes:
import { HttpClient } from '@angular/common/http';
For the import to work we do need the HttpClientModule
to be imported into our AppModule
, as shown here:
@NgModule({
declarations: [...],
imports: [
BrowserModule,
HttpClientModule,
...
],
...
})
export class AppModule { }
Each of the service classes would then declare the HttpClient
as a member, which is used to make the HTTP calls to backend microservices. From within...