Skip to main content
The HttpClient service is Angular’s primary interface for making HTTP requests. It provides methods for all common HTTP operations and returns RxJS Observables for handling asynchronous responses.

Class Definition

Importing

Methods

request()

Constructs an observable for a generic HTTP request.
string
required
HTTP method (GET, POST, PUT, DELETE, etc.)
string
required
The endpoint URL
object
Configuration options for the request
Observable<any>
An Observable of the HTTP response

get()

Constructs a GET request that interprets the body as JSON by default.
string
required
The endpoint URL
object
Configuration options (see request() method)
Observable<T>
An Observable of the response body (type T)

post()

Constructs a POST request that sends data to the server.
string
required
The endpoint URL
any
required
The content to post
object
Configuration options (see request() method)
Observable<T>
An Observable of the response body (type T)

put()

Constructs a PUT request that replaces a resource on the server.
string
required
The endpoint URL
any
required
The content to update
object
Configuration options (see request() method)
Observable<T>
An Observable of the response body (type T)

patch()

Constructs a PATCH request that partially updates a resource on the server.
string
required
The endpoint URL
any
required
The content to patch
object
Configuration options (see request() method)
Observable<T>
An Observable of the response body (type T)

delete()

Constructs a DELETE request that removes a resource from the server.
string
required
The endpoint URL
object
Configuration options (see request() method)
Observable<T>
An Observable of the response body (type T)
Constructs a HEAD request that retrieves only headers without the body.
string
required
The endpoint URL
object
Configuration options (see request() method)
Observable<T>
An Observable of the response (typically used with observe: ‘response’)

options()

Constructs an OPTIONS request that retrieves supported HTTP methods.
string
required
The endpoint URL
object
Configuration options (see request() method)
Observable<T>
An Observable of the response

jsonp()

Constructs a JSONP request for cross-domain requests.
JSONP requires the provideHttpClient() to be configured with withJsonpSupport().
string
required
The endpoint URL
string
required
The callback query parameter name
Observable<T>
An Observable of the response body (type T)

Usage Notes

Type Safety

Use TypeScript generics to ensure type safety:

Response Type Variations

The return type varies based on the observe and responseType options:

Progress Tracking

Track upload and download progress:

Error Handling

Handle errors using RxJS operators:

See Also

HTTP Overview

Introduction to Angular’s HTTP client

HttpInterceptor

Intercept and transform HTTP requests