MCPcopy Create free account
hub / github.com/angular/angular / provideHttpClient

Function provideHttpClient

packages/common/http/src/provider.ts:99–145  ·  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 `Configuration error: found both withXsrfConfiguration() and withNoXsrfProtection() in the same call to provideHttpClient(), which is a contradiction.`,
110 );
111 }
112
113 const hasBackendOverride =
114 featureKinds.has(HttpFeatureKind.Fetch) || featureKinds.has(HttpFeatureKind.Xhr);
115 if (featureKinds.has(HttpFeatureKind.RequestsMadeViaParent) && hasBackendOverride) {
116 throw new Error(
117 `Configuration error: withRequestsMadeViaParent() cannot be combined with withFetch() or withXhr() in the same call to provideHttpClient().`,
118 );
119 }
120 }
121
122 const providers: Provider[] = [
123 HttpClient,
124 FetchBackend,
125 HttpInterceptorHandler,
126 {provide: HttpHandler, useExisting: HttpInterceptorHandler},
127 {
128 provide: HttpBackend,
129 useFactory: () => {
130 return inject(FetchBackend);
131 },
132 },
133 {
134 provide: HTTP_INTERCEPTOR_FNS,
135 useValue: xsrfInterceptorFn,
136 multi: true,
137 },
138 ];
139
140 for (const feature of features) {
141 providers.push(...feature.ɵproviders);
142 }
143
144 return makeEnvironmentProviders(providers);
145}
146
147/**
148 * 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