provideHttpClient()

Registers the HttpClient and optional interceptor/fetch features.

Since Angular 15+ Spec ↗

Syntax

provideHttpClient(...features): EnvironmentProviders

Parameters

NameTypeRequiredDescription
features HttpFeature[] No Optional features like withInterceptors, withFetch.

Returns

EnvironmentProviders — Providers enabling HttpClient.

Examples

import { provideHttpClient, withInterceptors, withFetch } from '@angular/common/http';
import { authInterceptor } from './auth.interceptor';

export const appConfig = {
  providers: [
    provideHttpClient(
      withFetch(),
      withInterceptors([authInterceptor]),
    ),
  ],
};

Notes

Replaces HttpClientModule. withFetch() switches to the Fetch API (good for SSR), and withInterceptors registers functional interceptors. Add to bootstrapApplication providers; then inject(HttpClient) anywhere.