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: ...

Get Java EE 8 and Angular now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.