HttpRequest

class

An outgoing HTTP request with an optional typed body.

See more...

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

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

3 overloads...

constructor(method: 'DELETE' | 'GET' | 'HEAD' | 'JSONP' | 'OPTIONS', url: string, init?: { headers?: HttpHeaders; reportProgress?: boolean; params?: HttpParams; responseType?: 'arraybuffer' | 'blob' | 'json' | 'text'; withCredentials?: boolean; })

Parameters

method

Type: 'DELETE' | 'GET' | 'HEAD' | 'JSONP' | 'OPTIONS'.

url

Type: string.

init

Type: { headers?: HttpHeaders; reportProgress?: boolean; params?: HttpParams; responseType?: 'arraybuffer' | 'blob' | 'json' | 'text'; withCredentials?: boolean; }.

Optional. Default is undefined.

constructor(method: 'POST' | 'PUT' | 'PATCH', url: string, body: T | null, init?: { headers?: HttpHeaders; reportProgress?: boolean; params?: HttpParams; responseType?: 'arraybuffer' | 'blob' | 'json' | 'text'; withCredentials?: boolean; })

Parameters

method

Type: 'POST' | 'PUT' | 'PATCH'.

url

Type: string.

body

Type: T | null.

init

Type: { headers?: HttpHeaders; reportProgress?: boolean; params?: HttpParams; responseType?: 'arraybuffer' | 'blob' | 'json' | 'text'; withCredentials?: boolean; }.

Optional. Default is undefined.

constructor(method: string, url: string, body: T | null, init?: { headers?: HttpHeaders; reportProgress?: boolean; params?: HttpParams; responseType?: 'arraybuffer' | 'blob' | 'json' | 'text'; withCredentials?: boolean; })

Parameters

method

Type: string.

url

Type: string.

body

Type: T | null.

init

Type: { headers?: HttpHeaders; reportProgress?: boolean; params?: HttpParams; responseType?: 'arraybuffer' | 'blob' | 'json' | 'text'; withCredentials?: boolean; }.

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.

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.

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.

urlWithParams: string Read-only.

The outgoing URL with all URL parameters set.

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 | string | null

Parameters

There are no parameters.

Returns

ArrayBuffer | Blob | FormData | 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...

clone(): HttpRequest<T>

Parameters

There are no parameters.

Returns

HttpRequest<T>

clone(update: { headers?: HttpHeaders; reportProgress?: boolean; params?: HttpParams; responseType?: 'arraybuffer' | 'blob' | 'json' | 'text'; withCredentials?: boolean; body?: T | null; method?: string; url?: string; setHeaders?: { [name: string]: string | string[]; }; setParams?: { [param: string]: string; }; }): HttpRequest<T>

Parameters

update

Type: { headers?: HttpHeaders; reportProgress?: boolean; params?: HttpParams; responseType?: 'arraybuffer' | 'blob' | 'json' | 'text'; withCredentials?: boolean; body?: T | null; method?: string; url?: string; setHeaders?: { [name: string]: string | string[]; }; setParams?: { [param: string]: string; }; }.

Returns

HttpRequest<T>

clone<V>(update: { headers?: HttpHeaders; reportProgress?: boolean; params?: HttpParams; responseType?: 'arraybuffer' | 'blob' | 'json' | 'text'; withCredentials?: boolean; body?: V | null; method?: string; url?: string; setHeaders?: { [name: string]: string | string[]; }; setParams?: { [param: string]: string; }; }): HttpRequest<V>

Parameters

update

Type: { headers?: HttpHeaders; reportProgress?: boolean; params?: HttpParams; responseType?: 'arraybuffer' | 'blob' | 'json' | 'text'; withCredentials?: boolean; body?: V | null; method?: string; url?: string; setHeaders?: { [name: string]: string | string[]; }; setParams?: { [param: string]: string; }; }.

Returns

HttpRequest<V>

© 2010–2019 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://v6.angular.io/api/common/http/HttpRequest