Class ResponsesBuilder

A utility service to build responses.

Constructors

Properties

_config: SimpleConfig

The application configuration, to get the version and the postMessagesPrefix.

_statuses: Statuses

The uility service to get HTTP status codes.

Methods

  • Generates a basic HTML template for the service to use when generating a post message response.

    Parameters

    • title: string

      The HTML <title /> attribute.

    • code: string

      Javascript code to be wrapped on a <script /> tag.

    Returns string

  • Utility method used to make sure a recevied status is a valid status code. If the status is a string, the method will try to find the code from the statuses package.

    Parameters

    • status: string | number

      The status to normalize.

    Returns number

    If status is a string, but there's no valid code, it will return 200.

  • Generates and send an HTML response that emits a post message. The post message will be prefixed with the value of the configuration setting postMessagesPrefix.

    Parameters

    Returns void

  • Generates and sends a JSON response.

    Parameters

    Returns void

    Example: The generated looks like this.

    {
    metadata: {
    version: 'dev',
    status: 200,
    },
    data: { foo: 'bar' },
    }

Generated using TypeDoc