Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Response

A simple facade for the node http ServerResponse

Hierarchy

  • Response

Index

Constructors

constructor

  • new Response(response: ServerResponse): Response

Methods

binary

  • binary(payload: any): void
  • Since version 1.6 Sends binary payload to the client (would work for downloading) For displaying a video on a frontend use the stream() method

    Parameters

    • payload: any

    Returns void

end

  • end(callback?: function): void
  • Since 1.8 Ends the response

    Parameters

    • Optional callback: function
        • (...args: any[]): any
        • Parameters

          • Rest ...args: any[]

          Returns any

    Returns void

event

finished

  • finished(): boolean

json

  • Writes json representation of the given object to the response, but don't closes the stream

    deprecated

    since 1.5.1 Use respond() instead

    Parameters

    • payload: Object

    Returns Response

respond

  • respond(payload?: string | Promise<Object> | Stream | Object): void
  • Since version 1.5.1 you will use this to respond. You are now able to put in an promise (that you e.g. get from some database services) and can respond with it. On error it will respond with an error object that put the promise rejection reason as message

    Parameters

    • Optional payload: string | Promise<Object> | Stream | Object

    Returns void

send

  • send(): void

setHeader

  • setHeader(name: string, value: string | string[] | number): Response

status

  • status(status: number, message?: string): Response

stream

  • stream(payload: Stream): void
  • Since version 1.6 Takes a file stream and pipes the response Use this for serving things like music or videos e.g. for a web browser

    Parameters

    • payload: Stream

    Returns void

text

writeHead

  • writeHead(status: number, headerObject: object): Response