2022-11-04 00:10:05 +00:00
# HTTP: Setup for server communication
2022-10-07 00:06:43 +00:00
2023-08-17 05:11:14 +00:00
Before you can use `HttpClient` , you must add it to the application's [root dependency injector ](guide/dependency-injection ).
2022-11-04 00:10:05 +00:00
2023-11-11 07:26:10 +00:00
Most apps do so in the `providers` array of `ApplicationConfig` in `app.config.ts` .
2023-08-17 05:11:14 +00:00
2023-11-11 07:26:10 +00:00
< code-example header = "app.config.ts (excerpt)" path = "http/src/app/app.config.ts" region = "sketch" > < / code-example >
2022-11-04 00:10:05 +00:00
You can then inject the `HttpClient` service as a dependency of an application class, as shown in the following `ConfigService` example.
< code-example header = "app/config/config.service.ts (excerpt)" path = "http/src/app/config/config.service.ts" region = "proto" > < / code-example >
< div class = "alert is-helpful" >
2023-08-17 05:11:14 +00:00
You can run the < live-example name = "http" > < / live-example > that accompanies this guide.
2022-11-04 00:10:05 +00:00
The sample app does not require a data server.
It relies on the [Angular *in-memory-web-api* ](https://github.com/angular/angular/tree/main/packages/misc/angular-in-memory-web-api ), which replaces the *HttpClient* module's `HttpBackend` .
The replacement service simulates the behavior of a REST-like backend.
2023-08-17 05:11:14 +00:00
Look at the `bootstrapApplication()` method in `main.ts` to see how it is configured.
2022-11-04 00:10:05 +00:00
< / div >
2023-08-17 05:11:14 +00:00
@reviewed 2023-08-16