Skip to main content
Angular’s HTTP client provides a simplified API for HTTP functionality in your applications. It’s built on top of the browser’s native fetch or XMLHttpRequest APIs and provides a streamlined way to communicate with backend services.

Key Features

  • Observable-based API: All HTTP methods return RxJS Observables for powerful async operations
  • Request and response interceptors: Transform requests and responses globally
  • Typed request and response objects: Full TypeScript support with generic types
  • Streamlined error handling: Structured error responses
  • Testability: Built-in testing utilities for mocking HTTP requests
  • Progress events: Track upload and download progress
  • Request cancellation: Cancel in-flight requests when needed

Getting Started

Import HttpClient

To use the HTTP client, you need to import HttpClient and configure it in your application:

Provide HTTP Client

In your application configuration, provide the HTTP client:

Making Requests

The HttpClient service provides methods for all common HTTP verbs:
  • get() - Retrieve data from a server
  • post() - Send data to create a resource
  • put() - Send data to update a resource
  • patch() - Send data to partially update a resource
  • delete() - Delete a resource
  • head() - Retrieve headers only
  • options() - Retrieve supported HTTP methods
  • jsonp() - Make JSONP requests

Basic GET Request

POST Request with Body

Request Options

All HTTP methods accept an options object to customize the request:
HttpHeaders | object
HTTP headers to send with the request
HttpParams | object
URL query parameters
'json' | 'text' | 'blob' | 'arraybuffer'
Expected response format (defaults to ‘json’)
'body' | 'response' | 'events'
What to observe in the response (defaults to ‘body’)
boolean
Whether to send credentials (cookies) with the request
boolean
Whether to report upload/download progress events

Response Types

By default, HttpClient assumes JSON responses, but you can specify other types:

JSON Response (default)

Text Response

Blob Response

Observing Responses

Control what part of the response you want to observe:

Body Only (default)

Full Response

All Events

Error Handling

Handle HTTP errors using RxJS operators:

HTTP Headers

Work with HTTP headers using the HttpHeaders class:
Note: HttpHeaders is immutable, so set() returns a new instance.

URL Parameters

Add query parameters using HttpParams or a plain object:

Request Cancellation

Cancel in-flight requests by unsubscribing:

HttpClient

Complete API reference for the HttpClient service

HttpInterceptor

Intercept and transform HTTP requests and responses

See Also