Options
All
  • Public
  • Public/Protected
  • All
Menu

Class HttpRequest<T>

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.

Type parameters

  • T

Hierarchy

  • HttpRequest

Index

Constructors

constructor

  • new HttpRequest(method: "DELETE" | "GET" | "HEAD" | "JSONP" | "OPTIONS", url: string, init?: { headers?: HttpHeaders; params?: HttpParams; reportProgress?: boolean; responseType?: "arraybuffer" | "blob" | "json" | "text"; withCredentials?: boolean }): HttpRequest
  • new HttpRequest(method: "POST" | "PUT" | "PATCH", url: string, body: T | null, init?: { headers?: HttpHeaders; params?: HttpParams; reportProgress?: boolean; responseType?: "arraybuffer" | "blob" | "json" | "text"; withCredentials?: boolean }): HttpRequest
  • new HttpRequest(method: string, url: string, body: T | null, init?: { headers?: HttpHeaders; params?: HttpParams; reportProgress?: boolean; responseType?: "arraybuffer" | "blob" | "json" | "text"; withCredentials?: boolean }): HttpRequest
  • Parameters

    • method: "DELETE" | "GET" | "HEAD" | "JSONP" | "OPTIONS"
    • url: string
    • Optional init: { headers?: HttpHeaders; params?: HttpParams; reportProgress?: boolean; responseType?: "arraybuffer" | "blob" | "json" | "text"; withCredentials?: boolean }
      • Optional headers?: HttpHeaders
      • Optional params?: HttpParams
      • Optional reportProgress?: boolean
      • Optional responseType?: "arraybuffer" | "blob" | "json" | "text"
      • Optional withCredentials?: boolean

    Returns HttpRequest

  • Parameters

    • method: "POST" | "PUT" | "PATCH"
    • url: string
    • body: T | null
    • Optional init: { headers?: HttpHeaders; params?: HttpParams; reportProgress?: boolean; responseType?: "arraybuffer" | "blob" | "json" | "text"; withCredentials?: boolean }
      • Optional headers?: HttpHeaders
      • Optional params?: HttpParams
      • Optional reportProgress?: boolean
      • Optional responseType?: "arraybuffer" | "blob" | "json" | "text"
      • Optional withCredentials?: boolean

    Returns HttpRequest

  • Parameters

    • method: string
    • url: string
    • body: T | null
    • Optional init: { headers?: HttpHeaders; params?: HttpParams; reportProgress?: boolean; responseType?: "arraybuffer" | "blob" | "json" | "text"; withCredentials?: boolean }
      • Optional headers?: HttpHeaders
      • Optional params?: HttpParams
      • Optional reportProgress?: boolean
      • Optional responseType?: "arraybuffer" | "blob" | "json" | "text"
      • Optional withCredentials?: boolean

    Returns HttpRequest

Properties

Readonly body

body: T | null = 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.

Readonly headers

headers: HttpHeaders

Outgoing headers for this request.

Readonly method

method: string

The outgoing HTTP request method.

Readonly params

params: HttpParams

Outgoing URL parameters.

Readonly reportProgress

reportProgress: boolean = false

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.

Readonly responseType

responseType: "arraybuffer" | "blob" | "json" | "text" = "json"

The expected response type of the server.

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

Readonly url

url: string

Readonly urlWithParams

urlWithParams: string

The outgoing URL with all URL parameters set.

Readonly withCredentials

withCredentials: boolean = false

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

Methods

clone

  • clone(): HttpRequest<T>
  • clone(update: { body?: T | null; headers?: HttpHeaders; method?: string; params?: HttpParams; reportProgress?: boolean; responseType?: "arraybuffer" | "blob" | "json" | "text"; setHeaders?: {}; setParams?: {}; url?: string; withCredentials?: boolean }): HttpRequest<T>
  • clone<V>(update: { body?: V | null; headers?: HttpHeaders; method?: string; params?: HttpParams; reportProgress?: boolean; responseType?: "arraybuffer" | "blob" | "json" | "text"; setHeaders?: {}; setParams?: {}; url?: string; withCredentials?: boolean }): HttpRequest<V>
  • Returns HttpRequest<T>

  • Parameters

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

    Returns HttpRequest<T>

  • Type parameters

    • V

    Parameters

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

    Returns HttpRequest<V>

detectContentTypeHeader

  • 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.

    Returns string | null

serializeBody

  • serializeBody(): ArrayBuffer | Blob | FormData | string | null
  • Transform the free-form body into a serialized format suitable for transmission to the server.

    Returns ArrayBuffer | Blob | FormData | string | null

Generated using TypeDoc