{ "id": "api/common/http/HttpRequest", "title": "HttpRequest", "contents": "\n\n
\n
\n
\n \n API > @angular/common > @angular/common/http\n
\n \n
\n \n
\n

HttpRequestlink

\n \n \n \n \n \n
\n \n \n\n
\n \n
\n

An outgoing HTTP request with an optional typed body.

\n\n

See more...

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

Descriptionlink

\n

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

\n\n \n
\n\n \n\n\n\n\n\n\n

Constructorlink

\n\n\n \n \n \n \n \n \n \n\n \n\n \n \n
\n
\n \n
\n

3 overloads...

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

Optional. Default is undefined.

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

Optional. Default is undefined.

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

Optional. Default is undefined.

\n \n
\n\n \n\n\n \n\n \n
\n \n \n
\n
\n
\n\n\n\n\n
\n

Propertieslink

\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
PropertyDescription
\n \n body: T | null\n Read-Only\n \n

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

\n\n

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

\n\n
\n \n headers: HttpHeaders\n Read-Only\n \n

Outgoing headers for this request.

\n\n \n
\n \n context: HttpContext\n Read-Only\n \n

Shared and mutable context that can be used by interceptors

\n\n \n
\n \n reportProgress: boolean\n Read-Only\n \n

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

\n\n

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

\n\n
\n \n withCredentials: boolean\n Read-Only\n \n

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

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

The expected response type of the server.

\n\n

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

\n\n
\n \n method: string\n Read-Only\n \n

The outgoing HTTP request method.

\n\n \n
\n \n params: HttpParams\n Read-Only\n \n

Outgoing URL parameters.

\n\n

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

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

The outgoing URL with all URL parameters set.

\n\n \n
\n \n url: string\n Read-Only\n Declared in Constructor\n \n \n
\n
\n\n\n\n
\n

Methodslink

\n \n \n\n \n \n \n \n \n \n \n \n \n \n\n \n\n \n \n
\n
\n

\n serializeBody()\n \n link

\n \n
\n
\n

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

\n\n
\n
\n \n\n serializeBody(): ArrayBuffer | Blob | FormData | string | null\n\n \n\n
Parameters
\n

There are no parameters.

\n\n \n
Returns
\n

ArrayBuffer | Blob | FormData | string | null

\n\n \n\n\n \n\n \n
\n
\n\n \n \n\n \n \n \n \n \n \n \n \n \n \n\n \n \n \n\n \n \n
\n
\n

\n detectContentTypeHeader()\n \n link

\n \n
\n
\n

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

\n\n
\n
\n \n\n detectContentTypeHeader(): string | null\n\n \n\n
Parameters
\n

There are no parameters.

\n\n \n
Returns
\n

string | null

\n\n \n\n\n \n\n \n
\n
\n

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

\n\n
\n\n \n \n\n \n \n \n \n \n \n \n\n \n\n \n \n
\n
\n

\n clone()\n \n link

\n \n
\n
\n
\n \n
\n

3 overloads...

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

There are no parameters.

\n\n \n
Returns
\n

HttpRequest<T>

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

HttpRequest<T>

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

HttpRequest<V>

\n\n \n\n\n \n\n \n
\n \n \n
\n
\n
\n\n \n
\n\n\n\n \n\n\n
\n
\n\n\n" }