Options
All
  • Public
  • Public/Protected
  • All
Menu

Class HttpRequest<T>

A client-side HTTP request.

Instances are created by an WebClient instance, via one of the methods corresponding to the specific HTTP methods such as {@link WebClient#get}, etc...

The request shall be configured prior sending, the request is immutable and when a mutator method is called, a new request is returned allowing to expose the request in a public API and apply further customization.

After the request has been configured, the methods

  • {@link HttpRequest#send}
  • {@link HttpRequest#sendStream}
  • {@link HttpRequest#sendJson} ()}
  • {@link HttpRequest#sendForm}
can be called. The sendXXX methods perform the actual request, they can be called multiple times to perform the same HTTP request at different points in time.

The handler is called back with

  • an HttpResponse instance when the HTTP response has been received
  • a failure when the HTTP request failed (like a connection error) or when the HTTP response could not be obtained (like connection or unmarshalling errors)

Most of the time, this client will buffer the HTTP response fully unless a specific is used such as .

Type parameters

  • T

Hierarchy

  • HttpRequest

Index

Methods

addQueryParam

  • addQueryParam(paramName: string, paramValue: string): HttpRequest<T>
  • Add a query parameter to the request.

    Parameters

    • paramName: string
    • paramValue: string

    Returns HttpRequest<T>

as

  • Configure the request to decode the response with the responseCodec.

    Type parameters

    • U

    Parameters

    • responseCodec: BodyCodec<U>

    Returns HttpRequest<U>

authentication

  • Configure the request to perform HTTP Authentication.

    Performs a generic authentication using the credentials provided by the user. For the sake of validation safety it is recommended that is called to ensure that the credentials are applicable to the HTTP Challenged received on a previous request that returned a 401 response code.

    Parameters

    • credentials: any

    Returns HttpRequest<T>

basicAuthentication

  • basicAuthentication(id: string, password: string): HttpRequest<T>
  • basicAuthentication(id: Buffer, password: Buffer): HttpRequest<T>
  • Configure the request to perform basic access authentication.

    In basic HTTP authentication, a request contains a header field of the form 'Authorization: Basic <credentials>', where credentials is the base64 encoding of id and password joined by a colon.

    In practical terms the arguments are converted to a object.

    Parameters

    • id: string
    • password: string

    Returns HttpRequest<T>

  • Configure the request to perform basic access authentication.

    In basic HTTP authentication, a request contains a header field of the form 'Authorization: Basic <credentials>', where credentials is the base64 encoding of id and password joined by a colon.

    In practical terms the arguments are converted to a object.

    Parameters

    • id: Buffer
    • password: Buffer

    Returns HttpRequest<T>

bearerTokenAuthentication

  • bearerTokenAuthentication(bearerToken: string): HttpRequest<T>
  • Configure the request to perform bearer token authentication.

    In OAuth 2.0, a request contains a header field of the form 'Authorization: Bearer <bearerToken>', where bearerToken is the bearer token issued by an authorization server to access protected resources.

    In practical terms the arguments are converted to a object.

    Parameters

    • bearerToken: string

    Returns HttpRequest<T>

bodyCodec

  • bodyCodec(): BodyCodec<T>
  • Returns BodyCodec<T>

copy

  • Copy this request

    Returns HttpRequest<T>

expect

expectations

  • Returns ResponsePredicate

followRedirects

  • followRedirects(value: boolean): HttpRequest<T>
  • followRedirects(): boolean
  • Set whether to follow request redirections

    Parameters

    • value: boolean

    Returns HttpRequest<T>

  • Returns boolean

headers

  • headers(): MultiMap
  • Returns MultiMap

host

  • Configure the request to use a new host value.

    This overrides the host set by absolute URI requests

    Parameters

    • value: string

    Returns HttpRequest<T>

  • Returns string

method

  • method(value: HttpMethod): HttpRequest<T>
  • method(): HttpMethod
  • Configure the request to use a new method value.

    Parameters

    • value: HttpMethod

    Returns HttpRequest<T>

  • Returns HttpMethod

multipartMixed

  • multipartMixed(allow: boolean): HttpRequest<T>
  • multipartMixed(): boolean
  • Allow or disallow multipart mixed encoding when sending having files sharing the same file name.
    The default value is true.
    Set to false if you want to achieve the behavior for HTML5.

    Parameters

    • allow: boolean

    Returns HttpRequest<T>

  • Returns boolean

port

  • Configure the request to use a new port value.

    This overrides the port set by absolute URI requests

    Parameters

    • value: number

    Returns HttpRequest<T>

  • Returns number

proxy

  • proxy(proxyOptions: ProxyOptions): HttpRequest<T>
  • proxy(): ProxyOptions
  • Configure the request to set a proxy for this request.

    Setting proxy here supersedes the proxy set on the client itself

    Parameters

    • proxyOptions: ProxyOptions

    Returns HttpRequest<T>

  • Returns ProxyOptions

putHeader

  • Configure the request to set a new HTTP header.

    Parameters

    • name: string
    • value: string

    Returns HttpRequest<T>

  • Configure the request to set a new HTTP header with multiple values.

    Parameters

    • name: string
    • value: any

    Returns HttpRequest<T>

putHeaders

  • Configure the request to add multiple HTTP headers .

    Parameters

    • headers: MultiMap

    Returns HttpRequest<T>

queryParams

  • queryParams(): MultiMap
  • Return the current query parameters.

    Returns MultiMap

send

  • Send a request, the handler will receive the response as an HttpResponse.

    Returns PromiseLike<HttpResponse<T>>

  • Send a request, the handler will receive the response as an HttpResponse.

    Parameters

    Returns void

sendBuffer

  • sendBuffer(body: Buffer): PromiseLike<HttpResponse<T>>
  • sendBuffer(body: Buffer, handler: ((res: AsyncResult<HttpResponse<T>>) => void) | Handler<AsyncResult<HttpResponse<T>>>): void
  • Like {@link HttpRequest#send} but with an HTTP request body buffer.

    Parameters

    • body: Buffer

    Returns PromiseLike<HttpResponse<T>>

  • Like {@link HttpRequest#send} but with an HTTP request body buffer.

    Parameters

    Returns void

sendForm

  • sendForm(body: MultiMap): PromiseLike<HttpResponse<T>>
  • sendForm(body: MultiMap, handler: ((res: AsyncResult<HttpResponse<T>>) => void) | Handler<AsyncResult<HttpResponse<T>>>): void
  • sendForm(body: MultiMap, charset: string): PromiseLike<HttpResponse<T>>
  • sendForm(body: MultiMap, charset: string, handler: ((res: AsyncResult<HttpResponse<T>>) => void) | Handler<AsyncResult<HttpResponse<T>>>): void
  • Like {@link HttpRequest#send} but with an HTTP request body multimap encoded as form and the content type set to application/x-www-form-urlencoded.

    When the content type header is previously set to multipart/form-data it will be used instead.

    Parameters

    • body: MultiMap

    Returns PromiseLike<HttpResponse<T>>

  • Like {@link HttpRequest#send} but with an HTTP request body multimap encoded as form and the content type set to application/x-www-form-urlencoded.

    When the content type header is previously set to multipart/form-data it will be used instead.

    Parameters

    Returns void

  • Like {@link HttpRequest#send} but with an HTTP request body multimap encoded as form and the content type set to application/x-www-form-urlencoded.

    When the content type header is previously set to multipart/form-data it will be used instead.

    NOTE: the use of this method is strongly discouraged to use when the form is a application/x-www-form-urlencoded encoded form since the charset to use must be UTF-8.

    Parameters

    • body: MultiMap
    • charset: string

    Returns PromiseLike<HttpResponse<T>>

  • Like {@link HttpRequest#send} but with an HTTP request body multimap encoded as form and the content type set to application/x-www-form-urlencoded.

    When the content type header is previously set to multipart/form-data it will be used instead.

    NOTE: the use of this method is strongly discouraged to use when the form is a application/x-www-form-urlencoded encoded form since the charset to use must be UTF-8.

    Parameters

    • body: MultiMap
    • charset: string
    • handler: ((res: AsyncResult<HttpResponse<T>>) => void) | Handler<AsyncResult<HttpResponse<T>>>

    Returns void

sendJson

  • sendJson(body: any | null | undefined): PromiseLike<HttpResponse<T>>
  • sendJson(body: any | null | undefined, handler: ((res: AsyncResult<HttpResponse<T>>) => void) | Handler<AsyncResult<HttpResponse<T>>>): void
  • Like {@link HttpRequest#send} but with an HTTP request body object encoded as json and the content type set to application/json.

    Parameters

    • body: any | null | undefined

    Returns PromiseLike<HttpResponse<T>>

  • Like {@link HttpRequest#send} but with an HTTP request body object encoded as json and the content type set to application/json.

    Parameters

    • body: any | null | undefined
    • handler: ((res: AsyncResult<HttpResponse<T>>) => void) | Handler<AsyncResult<HttpResponse<T>>>

    Returns void

sendJsonObject

  • sendJsonObject(body: {}): PromiseLike<HttpResponse<T>>
  • sendJsonObject(body: {}, handler: ((res: AsyncResult<HttpResponse<T>>) => void) | Handler<AsyncResult<HttpResponse<T>>>): void
  • Like {@link HttpRequest#send} but with an HTTP request body object encoded as json and the content type set to application/json.

    Parameters

    • body: {}
      • [key: string]: any

    Returns PromiseLike<HttpResponse<T>>

  • Like {@link HttpRequest#send} but with an HTTP request body object encoded as json and the content type set to application/json.

    Parameters

    • body: {}
      • [key: string]: any
    • handler: ((res: AsyncResult<HttpResponse<T>>) => void) | Handler<AsyncResult<HttpResponse<T>>>

    Returns void

sendMultipartForm

  • sendMultipartForm(body: MultipartForm): PromiseLike<HttpResponse<T>>
  • sendMultipartForm(body: MultipartForm, handler: ((res: AsyncResult<HttpResponse<T>>) => void) | Handler<AsyncResult<HttpResponse<T>>>): void
  • Like {@link HttpRequest#send} but with an HTTP request body multimap encoded as form and the content type set to multipart/form-data. You may use this method to send attributes and upload files.

    Parameters

    • body: MultipartForm

    Returns PromiseLike<HttpResponse<T>>

  • Like {@link HttpRequest#send} but with an HTTP request body multimap encoded as form and the content type set to multipart/form-data. You may use this method to send attributes and upload files.

    Parameters

    Returns void

sendStream

  • sendStream(body: ReadStream<Buffer>): PromiseLike<HttpResponse<T>>
  • sendStream(body: ReadStream<Buffer>, handler: ((res: AsyncResult<HttpResponse<T>>) => void) | Handler<AsyncResult<HttpResponse<T>>>): void
  • Like {@link HttpRequest#send} but with an HTTP request body stream.

    Parameters

    • body: ReadStream<Buffer>

    Returns PromiseLike<HttpResponse<T>>

  • Like {@link HttpRequest#send} but with an HTTP request body stream.

    Parameters

    • body: ReadStream<Buffer>
    • handler: ((res: AsyncResult<HttpResponse<T>>) => void) | Handler<AsyncResult<HttpResponse<T>>>

    Returns void

setQueryParam

  • setQueryParam(paramName: string, paramValue: string): HttpRequest<T>
  • Set a query parameter to the request.

    Parameters

    • paramName: string
    • paramValue: string

    Returns HttpRequest<T>

setTemplateParam

  • setTemplateParam(paramName: string, paramValue: string): HttpRequest<T>
  • setTemplateParam(paramName: string, paramValue: string): HttpRequest<T>
  • setTemplateParam(paramName: string, paramValue: {}): HttpRequest<T>
  • Set a request URI template string parameter to the request, expanded when the request URI is a .

    Parameters

    • paramName: string
    • paramValue: string

    Returns HttpRequest<T>

  • Set a request URI template list parameter to the request, expanded when the request URI is a .

    Parameters

    • paramName: string
    • paramValue: string

    Returns HttpRequest<T>

  • Set a request URI template map parameter to the request, expanded when the request URI is a .

    Parameters

    • paramName: string
    • paramValue: {}
      • [key: string]: string

    Returns HttpRequest<T>

ssl

  • Configure the request whether to use SSL.

    This overrides the SSL value set by absolute URI requests

    Parameters

    • value: boolean

    Returns HttpRequest<T>

  • Returns boolean

templateParams

  • templateParams(): Variables
  • Return the current request URI template parameters.

    Returns Variables

timeout

  • timeout(value: number): HttpRequest<T>
  • timeout(): number
  • Configures the amount of time in milliseconds after which if the request does not return any data within the timeout period an TimeoutException fails the request.

    Setting zero or a negative value disables the timeout.

    Parameters

    • value: number

    Returns HttpRequest<T>

  • Returns number

traceOperation

  • traceOperation(traceOperation: string): HttpRequest<T>
  • traceOperation(): string
  • Trace operation name override.

    Parameters

    • traceOperation: string

    Returns HttpRequest<T>

  • Returns string

uri

  • Configure the request to use a new request URI value.

    This overrides the port set by absolute URI requests

    When the uri has query parameters, they are set in the {@link HttpRequest#queryParams}, overwriting any parameters previously set

    Parameters

    • value: string

    Returns HttpRequest<T>

  • Returns string

virtualHost

  • virtualHost(value: string): HttpRequest<T>
  • virtualHost(): string
  • Configure the request to use a virtual host value.

    Usually the header host (:authority pseudo header for HTTP/2) is set from the request host value since this host value resolves to the server IP address.

    Sometimes you need to set a host header for an address that does not resolve to the server IP address. The virtual host value overrides the value of the actual host header (:authority pseudo header for HTTP/2).

    The virtual host is also be used for SNI.

    Parameters

    • value: string

    Returns HttpRequest<T>

  • Returns string

Generated using TypeDoc