MCPcopy
hub / github.com/angular/angular / provideHttpClient

Function provideHttpClient

packages/common/http/src/provider.ts:99–139  ·  view source on GitHub ↗
(
  ...features: HttpFeature<HttpFeatureKind>[]
)

Source from the content-addressed store, hash-verified

97 * @see {@link withXhr}
98 */
99export function provideHttpClient(
100 ...features: HttpFeature<HttpFeatureKind>[]
101): EnvironmentProviders {
102 if (ngDevMode) {
103 const featureKinds = new Set(features.map((f) => f.ɵkind));
104 if (
105 featureKinds.has(HttpFeatureKind.NoXsrfProtection) &&
106 featureKinds.has(HttpFeatureKind.CustomXsrfConfiguration)
107 ) {
108 throw new Error(
109 ngDevMode
110 ? `Configuration error: found both withXsrfConfiguration() and withNoXsrfProtection() in the same call to provideHttpClient(), which is a contradiction.`
111 : '',
112 );
113 }
114 }
115
116 const providers: Provider[] = [
117 HttpClient,
118 FetchBackend,
119 HttpInterceptorHandler,
120 {provide: HttpHandler, useExisting: HttpInterceptorHandler},
121 {
122 provide: HttpBackend,
123 useFactory: () => {
124 return inject(FetchBackend);
125 },
126 },
127 {
128 provide: HTTP_INTERCEPTOR_FNS,
129 useValue: xsrfInterceptorFn,
130 multi: true,
131 },
132 ];
133
134 for (const feature of features) {
135 providers.push(...feature.ɵproviders);
136 }
137
138 return makeEnvironmentProviders(providers);
139}
140
141/**
142 * Adds one or more functional-style HTTP interceptors to the configuration of the `HttpClient`

Callers 15

hydration_spec.tsFile · 0.90
resource.spec.tsFile · 0.90
provider_spec.tsFile · 0.90
client_spec.tsFile · 0.90
module.tsFile · 0.90
request_spec.tsFile · 0.90
app.config.tsFile · 0.90
app.config.tsFile · 0.90

Calls 5

injectFunction · 0.90
makeEnvironmentProvidersFunction · 0.90
mapMethod · 0.80
hasMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…