taxum
    Preparing search index...

    The Router class is responsible for handling and routing HTTP requests based on specified paths and methods.

    It allows nesting of sub-routers, adding layers, defining fallback handlers, and processing requests.

    Index

    Constructors

    Methods

    • Makes an asynchronous HTTP call using the provided request object.

      Routes the request to the appropriate handler and returns the response. If no response is returned from the primary handler, it executes the fallback handler.

      This function is normally considered internal, but it can be used in unit- and integration testing to avoid spinning up a server.

      Parameters

      • req: HttpRequest

        the HTTP request object containing all necessary details for the call.

      Returns Promise<ReadonlyHttpResponse>

    • Sets a fallback handler for the service.

      The specified handler will be used as a fallback to handle any requests that do not match existing routes.

      Parameters

      • handler: HandlerFn

        the function to be used as a fallback handler.

      Returns this

    • Applies the specified layer to all previously registered routes.

      Parameters

      • layer: Layer

        the layer to be applied to the endpoints.

      Returns this

    • Nests a given router under a specific path.

      Parameters

      • path: string

        the base path where the nested router will be applied.

      • router: Router

        the router instance to be nested under the specified path.

      Returns this

    • Resets the fallback handler to the default.

      Returns this

    • Defines a route for a specified path and associates it with a method router.

      Parameters

      • path: string

        the URL path to define the route for.

      • methodRouter: MethodRouter

        the router that handles the methods for the given path.

      Returns this