Cookies concent notice

This site uses cookies from Google to deliver its services and to analyze traffic.
Learn more
Skip to main content
This site is no longer updated.Head to Angular.devHome
/

This is the archived documentation for Angular v17. Please visit angular.dev to see this page for the current version of Angular.

HttpRequest

An outgoing HTTP request with an optional typed body.

See more...

      
      class HttpRequest<T> {
  constructor(method: string, url: string, third?: T | { headers?: HttpHeaders; context?: HttpContext; reportProgress?: boolean; params?: HttpParams; responseType?: "arraybuffer" | "blob" | "text" | "json"; withCredentials?: boolean; transferCache?: boolean | { ...; }; }, fourth?: { headers?: HttpHeaders; context?: HttpContext; reportProgress?: boolean; params?: HttpParams; responseType?: "arraybuffer" | "blob" | "text" | "json"; withCredentials?: boolean; transferCache?: boolean | { ...; }; })
  body: T | null
  headers: HttpHeaders
  context: HttpContext
  reportProgress: boolean
  withCredentials: boolean
  responseType: 'arraybuffer' | 'blob' | 'json' | 'text'
  method: string
  params: HttpParams
  urlWithParams: string
  transferCache?: {...}
  url: string
serializeBody(): ArrayBuffer | Blob | FormData | URLSearchParams | string | null
detectContentTypeHeader(): string | null
clone(update: { headers?: HttpHeaders; context?: HttpContext; reportProgress?: boolean; params?: HttpParams; responseType?: "arraybuffer" | "blob" | "text" | "json"; ... 6 more ...; setParams?: { ...; }; } = {}): HttpRequest<any>
clone(): HttpRequest<T>
clone(update: { headers?: HttpHeaders; context?: HttpContext; reportProgress?: boolean; params?: HttpParams; responseType?: "arraybuffer" | "blob" | "text" | "json"; ... 6 more ...; setParams?: { ...; }; }): HttpRequest<T>
clone<V>(update: { headers?: HttpHeaders; context?: HttpContext; reportProgress?: boolean; params?: HttpParams; responseType?: "arraybuffer" | "blob" | "text" | "json"; ... 6 more ...; setParams?: { ...; }; }): HttpRequest<V> }

Description

HttpRequest represents an outgoing request, including URL, method, headers, body, and other request configuration options. Instances should be assumed to be immutable. To modify a HttpRequest, the clone method should be used.

Constructor

5 overloads...

Show All Hide All expand_more
Overload #1
      
      constructor(method: "GET" | "HEAD", url: string, init?: { headers?: HttpHeaders; context?: HttpContext; reportProgress?: boolean; params?: HttpParams; responseType?: "arraybuffer" | "blob" | "text" | "json"; withCredentials?: boolean; transferCache?: boolean | { ...; }; })
    
Parameters
method "GET" | "HEAD"
url string
init object

Optional. Default is undefined.


Overload #2
      
      constructor(method: "DELETE" | "JSONP" | "OPTIONS", url: string, init?: { headers?: HttpHeaders; context?: HttpContext; reportProgress?: boolean; params?: HttpParams; responseType?: "arraybuffer" | "blob" | "text" | "json"; withCredentials?: boolean; })
    
Parameters
method "DELETE" | "JSONP" | "OPTIONS"
url string
init object

Optional. Default is undefined.


Overload #3
      
      constructor(method: "POST", url: string, body: T, init?: { headers?: HttpHeaders; context?: HttpContext; reportProgress?: boolean; params?: HttpParams; responseType?: "arraybuffer" | "blob" | "text" | "json"; withCredentials?: boolean; transferCache?: boolean | { ...; }; })
    
Parameters
method "POST"
url string
body T
init object

Optional. Default is undefined.


Overload #4
      
      constructor(method: "PUT" | "PATCH", url: string, body: T, init?: { headers?: HttpHeaders; context?: HttpContext; reportProgress?: boolean; params?: HttpParams; responseType?: "arraybuffer" | "blob" | "text" | "json"; withCredentials?: boolean; })
    
Parameters
method "PUT" | "PATCH"
url string
body T
init object

Optional. Default is undefined.


Overload #5
      
      constructor(method: string, url: string, body: T, init?: { headers?: HttpHeaders; context?: HttpContext; reportProgress?: boolean; params?: HttpParams; responseType?: "arraybuffer" | "blob" | "text" | "json"; withCredentials?: boolean; transferCache?: boolean | { ...; }; })
    
Parameters
method string
url string
body T
init object

Optional. Default is undefined.

Properties

Property Description
body: T | null Read-Only

The request body, or null if one isn't set.

Bodies are not enforced to be immutable, as they can include a reference to any user-defined data type. However, interceptors should take care to preserve idempotence by treating them as such.

headers: HttpHeaders Read-Only

Outgoing headers for this request.

context: HttpContext Read-Only

Shared and mutable context that can be used by interceptors

reportProgress: boolean Read-Only

Whether this request should be made in a way that exposes progress events.

Progress events are expensive (change detection runs on each event) and so they should only be requested if the consumer intends to monitor them.

Note: The FetchBackend doesn't support progress report on uploads.

withCredentials: boolean Read-Only

Whether this request should be sent with outgoing credentials (cookies).

responseType: 'arraybuffer' | 'blob' | 'json' | 'text' Read-Only

The expected response type of the server.

This is used to parse the response appropriately before returning it to the requestee.

method: string Read-Only

The outgoing HTTP request method.

params: HttpParams Read-Only

Outgoing URL parameters.

To pass a string representation of HTTP parameters in the URL-query-string format, the HttpParamsOptions' fromString may be used. For example:

      
      new HttpParams({fromString: 'angular=awesome'})
    
urlWithParams: string Read-Only

The outgoing URL with all URL parameters set.

transferCache?: { includeHeaders?: string[]; } | boolean Read-Only

The HttpTransferCache option for the request

url: string Read-Only Declared in Constructor

Methods

Transform the free-form body into a serialized format suitable for transmission to the server.

      
      serializeBody(): ArrayBuffer | Blob | FormData | URLSearchParams | string | null
    
Parameters

There are no parameters.

Returns

ArrayBuffer | Blob | FormData | URLSearchParams | string | null

Examine the body and attempt to infer an appropriate MIME type for it.

      
      detectContentTypeHeader(): string | null
    
Parameters

There are no parameters.

Returns

string | null

If no such type can be inferred, this method will return null.

3 overloads...

Show All Hide All expand_more
Overload #1
      
      clone(): HttpRequest<T>
    
Parameters

There are no parameters.

Returns

HttpRequest<T>


Overload #2
      
      clone(update: { headers?: HttpHeaders; context?: HttpContext; reportProgress?: boolean; params?: HttpParams; responseType?: "arraybuffer" | "blob" | "text" | "json"; ... 6 more ...; setParams?: { ...; }; }): HttpRequest<T>
    
Parameters
update object
Returns

HttpRequest<T>


Overload #3
      
      clone<V>(update: { headers?: HttpHeaders; context?: HttpContext; reportProgress?: boolean; params?: HttpParams; responseType?: "arraybuffer" | "blob" | "text" | "json"; ... 6 more ...; setParams?: { ...; }; }): HttpRequest<V>
    
Parameters
update object
Returns

HttpRequest<V>