Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Response

Hierarchy

  • Response

Index

Constructors

constructor

  • new Response(status: number, headers: string[][] | any, body: any, isRawBody?: boolean): Response
  • Constructs a new Response, with the given status code, headers, and body. The body will be encoded as JSON by default. Use encodeAs('raw') to disable JSON encoding.

    Parameters

    • status: number
    • headers: string[][] | any
    • body: any
    • Optional isRawBody: boolean

    Returns Response

Properties

body

body: string | Buffer

Body of the response.

headers

headers: string[][]

Headers for the response, as an array of [key, value] tuple arrays.

status

status: number

unencodedBody

unencodedBody: any

Stores the raw, unencoded body in case the user calls encodeAs()

Accessors

encoding

  • get encoding(): "raw" | "json"

Methods

encodeAs

  • Change the encoding of the body in the response. By default, Response will encode the body contents as JSON, even if the type of the value is a string. To send a body which is not JSON, you must call encodeAs('raw').

    Parameters

    Returns this

header

  • header(name: string, value: string): this

throw

  • throw(): void

Static accepted

Static badGateway

Static badRequest

Static conflict

Static continue

Static created

  • created(url: string, body: any): Response

Static expectationFailed

  • expectationFailed(body?: any): Response

Static forbidden

Static found

Static gatewayTimeout

Static gone

Static httpVersionNotSupported

  • httpVersionNotSupported(body?: any): Response

Static lengthRequired

Static methodNotAllowed

  • methodNotAllowed(allowedMethods: string, body?: any): Response
  • Return a 405 Method Not Allowed response with the given body (will be encoded as JSON, append encodeAs('raw') to disable).

    Parameters

    • allowedMethods: string
    • Optional body: any

    Returns Response

Static movedPermanently

  • movedPermanently(url: any, body?: any): Response

Static multipleChoices

  • Return a 300 Multiple Choices response with the given body (will be encoded as JSON, append encodeAs('raw') to disable). There is no standard format for the body, but you should indicate Content-Type, and ideally provide a Location header indicating the server's preferred choice.

    Parameters

    • body: any

    Returns Response

Static noContent

Static nonAuthoritativeInformation

  • nonAuthoritativeInformation(body: any): Response

Static notAcceptable

Static notFound

Static notImplemented

Static notModified

Static ok

Static partialContent

Static paymentRequired

  • Return a 402 Payment Required response with the given body (will be encoded as JSON, append encodeAs('raw') to disable). Caution: This status code has not been formally specified.

    Parameters

    • Optional body: any

    Returns Response

Static preconditionFailed

  • preconditionFailed(body?: any): Response

Static processing

Static proxyAuthenticationRequired

  • proxyAuthenticationRequired(challenge: any, body?: any): Response

Static rangeNotSatisfiable

  • rangeNotSatisfiable(body?: any): Response

Static requestTimeout

Static requestTooLarge

Static resetContent

Static seeOther

  • seeOther(url: any, body?: any): Response
  • Return a 303 See Other response with the given body (will be encoded as JSON, append encodeAs('raw') to disable). Use this after a new resource is created from a PUT or POST request to send the user agent to the new resource without causing them to redirect future requests to the POST/PUT endpoint itself.

    Parameters

    • url: any
    • Optional body: any

    Returns Response

Static serverError

Static serviceUnavailable

  • serviceUnavailable(body?: any): Response

Static switchingProtocols

  • switchingProtocols(body?: any): Response

Static temporaryRedirect

  • temporaryRedirect(url: any, body?: any): Response

Static unauthorized

Static unsupportedMediaType

  • unsupportedMediaType(body?: any): Response

Static uriTooLong

Static useProxy

  • useProxy(url: any, body?: any): Response
  • Return a 305 Use Proxy response with the given body (will be encoded as JSON, append encodeAs('raw') to disable). Use this if you are restricting requests only to approved proxies, and the user is not an approved proxy.

    Parameters

    • url: any
    • Optional body: any

    Returns Response

Generated using TypeDoc