Options
All
  • Public
  • Public/Protected
  • All
Menu

Class HandlerBuilder

Class that can be used to build HTTP request handlers for express js. Breaks down requests into three distinct phases:

(1) Request mapping: Generate a JSON object from the incoming HTTP request

(2) Request processing: Process the JSON object and return a response

(3) Response mapping: Generate an HTTP response based on the JSON response

Hierarchy

  • HandlerBuilder

Index

Constructors

constructor

Properties

Private _handler

_handler: RequestHandler

Private _handlerName

_handlerName: string

Private _inputMapper

_inputMapper: InputMapper

Private _outputMapper

_outputMapper: OutputMapper

Private Optional _schema

_schema: __type

Methods

build

  • build(): Handler
  • Builds a request handler function that can be assigned to expressjs routes.

    Returns Handler

    An expressjs request handler.

setInputMapper

  • Sets the input mapping for the handler.

    Parameters

    • mapping: object | InputMapper

      A mapping function that maps the HTTP request to an input object, or, a map that maps input properties to the corresponding values from the HTTP request. Supported mapping values include:

         1. params: Maps values from req.params to the input
         2. body: Maps values from req.body to the input
      

    Returns HandlerBuilder

    A reference to the handler builder, to be used for function chaining.

setOutputMapper

  • Sets the output mapping for the handler.

    Parameters

    • mapping: OutputMapper

      A mapping function that maps the output of the handler function to an HTTP response object.

    Returns HandlerBuilder

    A reference to the handler builder, to be used for function chaining.

setSchema

  • Sets the schema to be used when validating mapped input objects.

    Parameters

    • schema: __type

      A JSON schema object that can be used to validate the mapped input.

    Returns HandlerBuilder

    A reference to the handler builder, to be used for function chaining.

Static Private DEFAULT_INPUT_MAPPER

  • DEFAULT_INPUT_MAPPER(): IInput

Static Private DEFAULT_OUTPUT_MAPPER

  • DEFAULT_OUTPUT_MAPPER(data: any, res: Response): void

Generated using TypeDoc