HttpRequest

class

npm Package @angular/common
Module import { HttpRequest } from '@angular/common/http';
Source common/http/src/request.ts

Overview

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

Description

An outgoing HTTP request with an optional typed body.

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

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

Overloads

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

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

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

Members

get body: T | null

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.

get headers: HttpHeaders

Outgoing headers for this request.

get reportProgress: boolean

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.

get withCredentials: boolean

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

get responseType: 'arraybuffer' | 'blob' | 'json' | 'text'

The expected response type of the server.

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

get method: string

The outgoing HTTP request method.

get params: HttpParams

Outgoing URL parameters.

get urlWithParams: string

The outgoing URL with all URL parameters set.

get url: string

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

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

detectContentTypeHeader(): string | null

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

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

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

Overloads

clone(): 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>

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>

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