routing-controllers

  • Version 0.9.0
  • Published
  • 938 kB
  • 12 dependencies
  • MIT license

Install

npm i routing-controllers
yarn add routing-controllers
pnpm add routing-controllers

Overview

Create structured, declarative and beautifully organized class-based controllers with heavy decorators usage for Express / Koa using TypeScript.

Index

Functions

Classes

Interfaces

Type Aliases

Functions

function All

All: { (route?: RegExp): Function; (route?: string): Function };
  • Registers an action to be executed when a request comes on a given route. Must be applied on a controller action.

function Authorized

Authorized: {
(): Function;
(role: any): Function;
(roles: any[]): Function;
(role: Function): Function;
};
  • Marks controller action to have a special access. Authorization logic must be defined in routing-controllers settings.

function Body

Body: (options?: BodyOptions) => Function;
  • Allows to inject a request body value to the controller action parameter. Must be applied on a controller action parameter.

function BodyParam

BodyParam: (name: string, options?: ParamOptions) => Function;
  • Takes partial data of the request body. Must be applied on a controller action parameter.

function ContentType

ContentType: (contentType: string) => Function;
  • Sets response Content-Type. Must be applied on a controller action.

function Controller

Controller: (baseRoute?: string, options?: ControllerOptions) => Function;
  • Defines a class as a controller. Each decorated controller method is served as a controller action. Controller actions are executed when request come.

    Parameter baseRoute

    Extra path you can apply as a base route to all controller actions

    Parameter options

    Extra options that apply to all controller actions

function CookieParam

CookieParam: (
name: string,
options?: ParamOptions
) => (object: Object, methodName: string, index: number) => void;
  • Injects a request's cookie value to the controller action parameter. Must be applied on a controller action parameter.

function CookieParams

CookieParams: () => (object: Object, methodName: string, index: number) => void;
  • Injects all request's cookies to the controller action parameter. Must be applied on a controller action parameter.

function createExecutor

createExecutor: <T extends BaseDriver>(
driver: T,
options?: RoutingControllersOptions
) => void;
  • Registers all loaded actions in your express application.

function createExpressServer

createExpressServer: (options?: RoutingControllersOptions) => any;
  • Registers all loaded actions in your express application.

function createKoaServer

createKoaServer: (options?: RoutingControllersOptions) => any;
  • Registers all loaded actions in your koa application.

function createParamDecorator

createParamDecorator: (
options: CustomParameterDecorator
) => (object: Object, method: string, index: number) => void;
  • Registers custom parameter decorator used in the controller actions.

function createServer

createServer: <T extends BaseDriver>(
driver: T,
options?: RoutingControllersOptions
) => any;
  • Registers all loaded actions in your application using selected driver.

function Ctx

Ctx: () => Function;
  • Injects a Koa's Context object to the controller action parameter. Must be applied on a controller action parameter.

function CurrentUser

CurrentUser: (options?: {
required?: boolean;
}) => (object: Object, methodName: string, index: number) => void;
  • Injects currently authorized user. Authorization logic must be defined in routing-controllers settings.

function Delete

Delete: {
(route?: RegExp, options?: HandlerOptions): Function;
(route?: string, options?: HandlerOptions): Function;
};
  • Registers a controller method to be executed when DELETE request comes on a given route. Must be applied on a controller action.

function Get

Get: {
(route?: RegExp, options?: HandlerOptions): Function;
(route?: string, options?: HandlerOptions): Function;
};
  • Registers an action to be executed when GET request comes on a given route. Must be applied on a controller action.

function getFromContainer

getFromContainer: <T>(
someClass: ClassConstructor<T> | Function,
action?: Action
) => T;
  • Gets the IOC container used by this library.

    Parameter someClass

    A class constructor to resolve

    Parameter action

    The request/response context that someClass is being resolved for

function getMetadataArgsStorage

getMetadataArgsStorage: () => MetadataArgsStorage;
  • Gets metadata args storage. Metadata args storage follows the best practices and stores metadata in a global variable.

Head: {
(route?: RegExp, options?: HandlerOptions): Function;
(route?: string, options?: HandlerOptions): Function;
};
  • Registers an action to be executed when HEAD request comes on a given route. Must be applied on a controller action.

Header: (name: string, value: string) => Function;
  • Sets response header. Must be applied on a controller action.

function HeaderParam

HeaderParam: (name: string, options?: ParamOptions) => Function;
  • Injects a request's http header value to the controller action parameter. Must be applied on a controller action parameter.

function HeaderParams

HeaderParams: () => Function;
  • Injects all request's http headers to the controller action parameter. Must be applied on a controller action parameter.

function HttpCode

HttpCode: (code: number) => Function;
  • Sets response HTTP status code. Http code will be set only when controller action is successful. In the case if controller action rejects or throws an exception http code won't be applied. Must be applied on a controller action.

function Interceptor

Interceptor: (options?: { priority?: number }) => Function;
  • Registers a global interceptor.

function JsonController

JsonController: (
baseRoute?: string,
options?: ControllerOptions
) => (object: Function) => void;
  • Defines a class as a JSON controller. If JSON controller is used, then all controller actions will return a serialized json data, and its response content-type always will be application/json.

    Parameter baseRoute

    Extra path you can apply as a base route to all controller actions

    Parameter options

    Extra options that apply to all controller actions

function Location

Location: (url: string) => Function;
  • Sets Location header with given value to the response. Must be applied on a controller action.

function Method

Method: {
(method: ActionType, route?: RegExp, options?: HandlerOptions): Function;
(method: ActionType, route?: string, options?: HandlerOptions): Function;
};
  • Registers an action to be executed when request with specified method comes on a given route. Must be applied on a controller action.

function Middleware

Middleware: (options: {
type: 'after' | 'before';
priority?: number;
}) => Function;
  • Marks given class as a middleware. Allows to create global middlewares and control order of middleware execution.

function OnNull

OnNull: { (code: number): Function; (error: Function): Function };
  • Used to set specific HTTP status code when result returned by a controller action is equal to null. Must be applied on a controller action.

function OnUndefined

OnUndefined: { (code: number): Function; (error: Function): Function };
  • Used to set specific HTTP status code when result returned by a controller action is equal to undefined. Must be applied on a controller action.

function Param

Param: (name: string) => Function;
  • Injects a request's route parameter value to the controller action parameter. Must be applied on a controller action parameter.

function Params

Params: (options?: ParamOptions) => Function;
  • Injects all request's route parameters to the controller action parameter. Must be applied on a controller action parameter.

function Patch

Patch: {
(route?: RegExp, options?: HandlerOptions): Function;
(route?: string, options?: HandlerOptions): Function;
};
  • Registers an action to be executed when PATCH request comes on a given route. Must be applied on a controller action.

function Post

Post: {
(route?: RegExp, options?: HandlerOptions): Function;
(route?: string, options?: HandlerOptions): Function;
};
  • Registers an action to be executed when POST request comes on a given route. Must be applied on a controller action.

function Put

Put: {
(route?: RegExp, options?: HandlerOptions): Function;
(route?: string, options?: HandlerOptions): Function;
};
  • Registers an action to be executed when PUT request comes on a given route. Must be applied on a controller action.

  • Registers an action to be executed when POST request comes on a given route. Must be applied on a controller action.

function QueryParam

QueryParam: (name: string, options?: ParamOptions) => Function;
  • Injects a request's query parameter value to the controller action parameter. Must be applied on a controller action parameter.

function QueryParams

QueryParams: (options?: ParamOptions) => Function;
  • Injects all request's query parameters to the controller action parameter. Must be applied on a controller action parameter.

function Redirect

Redirect: (url: string) => Function;
  • Sets Redirect header with given value to the response. Must be applied on a controller action.

function Render

Render: (template: string) => Function;
  • Specifies a template to be rendered by a controller action. Must be applied on a controller action.

function Req

Req: () => Function;
  • Injects a Request object to the controller action parameter. Must be applied on a controller action parameter.

function Res

Res: () => Function;
  • Injects a Response object to the controller action parameter. Must be applied on a controller action parameter.

function ResponseClassTransformOptions

ResponseClassTransformOptions: (options: any) => Function;
  • Options to be set to class-transformer for the result of the response.

function Session

Session: (options?: ParamOptions) => ParameterDecorator;
  • Injects a Session object to the controller action parameter. Must be applied on a controller action parameter.

function SessionParam

SessionParam: (
propertyName: string,
options?: ParamOptions
) => ParameterDecorator;
  • Injects a Session object property to the controller action parameter. Must be applied on a controller action parameter.

function State

State: (objectName?: string) => Function;
  • Injects a State object to the controller action parameter. Must be applied on a controller action parameter.

function UploadedFile

UploadedFile: (name: string, options?: UploadOptions) => Function;
  • Injects an uploaded file object to the controller action parameter. Must be applied on a controller action parameter.

function UploadedFiles

UploadedFiles: (name: string, options?: UploadOptions) => Function;
  • Injects all uploaded files to the controller action parameter. Must be applied on a controller action parameter.

function UseAfter

UseAfter: {
(...middlewares: Array<Function>): Function;
(
...middlewares: ((context: any, next: () => Promise<any>) => Promise<any>)[]
): Function;
(
...middlewares: ((request: any, response: any, next: Function) => any)[]
): Function;
};
  • Specifies a given middleware to be used for controller or controller action AFTER the action executes. Must be set to controller action or controller class.

function UseBefore

UseBefore: {
(...middlewares: Array<Function>): Function;
(
...middlewares: ((context: any, next: () => Promise<any>) => Promise<any>)[]
): Function;
(
...middlewares: ((request: any, response: any, next: Function) => any)[]
): Function;
};
  • Specifies a given middleware to be used for controller or controller action BEFORE the action executes. Must be set to controller action or controller class.

function useContainer

useContainer: (iocAdapter: IocAdapter, options?: UseContainerOptions) => void;
  • Sets container to be used by this library.

function useExpressServer

useExpressServer: <T>(
expressServer: T,
options?: RoutingControllersOptions
) => T;
  • Registers all loaded actions in your express application.

function UseInterceptor

UseInterceptor: {
(...interceptors: Array<Function>): Function;
(...interceptors: ((action: Action, result: any) => any)[]): Function;
};
  • Specifies a given interceptor middleware or interceptor function to be used for controller or controller action. Must be set to controller action or controller class.

function useKoaServer

useKoaServer: <T>(koaApp: T, options?: RoutingControllersOptions) => T;
  • Registers all loaded actions in your koa application.

Classes

class ActionMetadata

class ActionMetadata {}
  • Action metadata.

constructor

constructor(
controllerMetadata: ControllerMetadata,
args: ActionMetadataArgs,
globalOptions: RoutingControllersOptions
);

    property appendParams

    appendParams?: (action: Action) => any[];
    • Params to be appended to the method call.

    property authorizedRoles

    authorizedRoles: any[];
    • Roles set by decorator.

    property bodyExtraOptions

    bodyExtraOptions: any;
    • Extra options used by decorator.

    property controllerMetadata

    controllerMetadata: ControllerMetadata;
    • Action's controller.

    property fullRoute

    fullRoute: string | RegExp;
    • Full route to this action (includes controller base route).

    property headers

    headers: { [name: string]: any };
    • Response headers to be set.

    property interceptors

    interceptors: InterceptorMetadata[];
    • Action's use interceptors.

    property isAuthorizedUsed

    isAuthorizedUsed: boolean;
    • Indicates if this action uses Authorized decorator.

    property isBodyUsed

    isBodyUsed: boolean;
    • Indicates if this action uses Body.

    property isFilesUsed

    isFilesUsed: boolean;
    • Indicates if this action uses Uploaded Files.

    property isFileUsed

    isFileUsed: boolean;
    • Indicates if this action uses Uploaded File.

    property isJsonTyped

    isJsonTyped: boolean;
    • Indicates if controller of this action is json-typed.

    property method

    method: string;
    • Object's method that will be executed on this action.

    property methodOverride

    methodOverride?: (
    actionMetadata: ActionMetadata,
    action: Action,
    params: any[]
    ) => Promise<any> | any;
    • Special function that will be called instead of orignal method of the target.

    property nullResultCode

    nullResultCode: number | Function;
    • Http code to be used on null action returned content.

    property options

    options: HandlerOptions;
    • Action-specific options.

    property params

    params: ParamMetadata[];
    • Action's parameters.

    property redirect

    redirect: string;
    • Specifies redirection url for this action.

    property renderedTemplate

    renderedTemplate: string;
    • Rendered template to be used for this controller action.

    property responseClassTransformOptions

    responseClassTransformOptions: any;
    • Class-transformer options for the action response content.

    property route

    route: string | RegExp;
    • Route to be registered for the action.

    property successHttpCode

    successHttpCode: number;
    • Http code to be set on successful response.

    property target

    target: Function;
    • Class on which's method this action is attached.

    property type

    type: ActionType;
    • Action type represents http method used for the registered route. Can be one of the value defined in ActionTypes class.

    property undefinedResultCode

    undefinedResultCode: number | Function;
    • Http code to be used on undefined action returned content.

    property uses

    uses: UseMetadata[];
    • Action's use metadatas.

    method appendBaseRoute

    static appendBaseRoute: (
    baseRoute: string,
    route: RegExp | string
    ) => string | RegExp;
    • Appends base route to a given regexp route.

    method build

    build: (responseHandlers: ResponseHandlerMetadata[]) => void;
    • Builds everything action metadata needs. Action metadata can be used only after its build.

    method callMethod

    callMethod: (params: any[], action: Action) => any;
    • Calls action method. Action method is an action defined in a user controller.

    class BadRequestError

    class BadRequestError extends HttpError {}
    • Exception for 400 HTTP error.

    constructor

    constructor(message?: string);

      property name

      name: string;

        class BaseDriver

        abstract class BaseDriver {}
        • Base driver functionality for all other drivers. Abstract layer to organize controllers integration with different http server implementations.

        property app

        app: any;
        • Reference to the underlying framework app object.

        property authorizationChecker

        authorizationChecker?: AuthorizationChecker;
        • Special function used to check user authorization roles per request. Must return true or promise with boolean true resolved for authorization to succeed.

        property classToPlainTransformOptions

        classToPlainTransformOptions: any;
        • Global class transformer options passed to class-transformer during classToPlain operation. This operation is being executed when server returns response to user.

        property cors

        cors?: boolean | Object;
        • Indicates if cors are enabled. This requires installation of additional module (cors for express and kcors for koa).

        property currentUserChecker

        currentUserChecker?: CurrentUserChecker;
        • Special function used to get currently authorized user.

        property developmentMode

        developmentMode: boolean;
        • Indicates if routing-controllers should operate in development mode.

        property enableValidation

        enableValidation: boolean;
        • Indicates if class-validator should be used or not.

        property errorOverridingMap

        errorOverridingMap: { [key: string]: any };
        • Map of error overrides.

        property isDefaultErrorHandlingEnabled

        isDefaultErrorHandlingEnabled: boolean;
        • Indicates if default routing-controllers error handler should be used or not.

        property plainToClassTransformOptions

        plainToClassTransformOptions: any;
        • Global class transformer options passed to class-transformer during plainToClass operation. This operation is being executed when parsing user parameters.

        property routePrefix

        routePrefix: string;
        • Global application prefix.

        property useClassTransformer

        useClassTransformer: boolean;
        • Indicates if class-transformer should be used or not.

        property validationOptions

        validationOptions: any;
        • Global class-validator options passed during validate operation.

        method getParamFromRequest

        abstract getParamFromRequest: (
        actionOptions: Action,
        param: ParamMetadata
        ) => any;
        • Gets param from the request.

        method handleError

        abstract handleError: (
        error: any,
        action: ActionMetadata,
        options: Action
        ) => any;
        • Defines an algorithm of how to handle error during executing controller action.

        method handleSuccess

        abstract handleSuccess: (
        result: any,
        action: ActionMetadata,
        options: Action
        ) => void;
        • Defines an algorithm of how to handle success result of executing controller action.

        method initialize

        abstract initialize: () => void;
        • Initializes the things driver needs before routes and middleware registration.

        method merge

        protected merge: (obj1: any, obj2: any) => any;

          method processJsonError

          protected processJsonError: (error: any) => any;

            method processTextError

            protected processTextError: (error: any) => any;

              method registerAction

              abstract registerAction: (
              action: ActionMetadata,
              executeCallback: (options: Action) => any
              ) => void;
              • Registers action in the driver.

              method registerMiddleware

              abstract registerMiddleware: (middleware: MiddlewareMetadata) => void;
              • Registers given middleware.

              method registerRoutes

              abstract registerRoutes: () => void;
              • Registers all routes in the framework.

              method transformResult

              protected transformResult: (
              result: any,
              action: ActionMetadata,
              options: Action
              ) => any;

                class ControllerMetadata

                class ControllerMetadata {}
                • Controller metadata.

                constructor

                constructor(args: ControllerMetadataArgs);

                  property actions

                  actions: ActionMetadata[];
                  • Controller actions.

                  property authorizedRoles

                  authorizedRoles: any[];
                  • Roles set by decorator.

                  property interceptors

                  interceptors: InterceptorMetadata[];
                  • Middleware "use"-s applied to a whole controller.

                  property isAuthorizedUsed

                  isAuthorizedUsed: boolean;
                  • Indicates if this action uses Authorized decorator.

                  property options

                  options: ControllerOptions;
                  • Options that apply to all controller actions.

                  property route

                  route: string;
                  • Base route for all actions registered in this controller.

                  property target

                  target: Function;
                  • Indicates object which is used by this controller.

                  property type

                  type: 'default' | 'json';
                  • Controller type. Can be default or json-typed. Json-typed controllers operate with json requests and responses.

                  property uses

                  uses: UseMetadata[];
                  • Middleware "use"-s applied to a whole controller.

                  method build

                  build: (responseHandlers: ResponseHandlerMetadata[]) => void;
                  • Builds everything controller metadata needs. Controller metadata should be used only after its build.

                  method getInstance

                  getInstance: (action: Action) => any;
                  • Gets instance of the controller.

                    Parameter action

                    Details around the request session

                  class ExpressDriver

                  class ExpressDriver extends BaseDriver {}
                  • Integration with express framework.

                  constructor

                  constructor(express?: any);

                    property express

                    express?: any;

                      method getParamFromRequest

                      getParamFromRequest: (action: Action, param: ParamMetadata) => any;
                      • Gets param from the request.

                      method handleError

                      handleError: (
                      error: any,
                      action: ActionMetadata | undefined,
                      options: Action
                      ) => any;
                      • Handles result of failed executed controller action.

                      method handleSuccess

                      handleSuccess: (result: any, action: ActionMetadata, options: Action) => void;
                      • Handles result of successfully executed controller action.

                      method initialize

                      initialize: () => void;
                      • Initializes the things driver needs before routes and middlewares registration.

                      method loadBodyParser

                      protected loadBodyParser: () => any;
                      • Dynamically loads body-parser module.

                      method loadExpress

                      protected loadExpress: () => void;
                      • Dynamically loads express module.

                      method loadMulter

                      protected loadMulter: () => any;
                      • Dynamically loads multer module.

                      method prepareMiddlewares

                      protected prepareMiddlewares: (uses: UseMetadata[]) => Function[];
                      • Creates middlewares from the given "use"-s.

                      method registerAction

                      registerAction: (
                      actionMetadata: ActionMetadata,
                      executeCallback: (options: Action) => any
                      ) => void;
                      • Registers action in the driver.

                      method registerMiddleware

                      registerMiddleware: (middleware: MiddlewareMetadata) => void;
                      • Registers middleware that run before controller actions.

                      method registerRoutes

                      registerRoutes: () => void;
                      • Registers all routes in the framework.

                      class ForbiddenError

                      class ForbiddenError extends HttpError {}
                      • Exception for 403 HTTP error.

                      constructor

                      constructor(message?: string);

                        property name

                        name: string;

                          class HttpError

                          class HttpError extends Error {}
                          • Used to throw HTTP errors. Just do throw new HttpError(code, message) in your controller action and default error handler will catch it and give in your response given code and message .

                          constructor

                          constructor(httpCode: number, message?: string);

                            property httpCode

                            httpCode: number;

                              class InterceptorMetadata

                              class InterceptorMetadata {}
                              • "Use interceptor" metadata.

                              constructor

                              constructor(args: UseInterceptorMetadataArgs);

                                property global

                                global: boolean;
                                • Indicates if this interceptor is global or not.

                                property interceptor

                                interceptor: Function;
                                • Interceptor class or function to be executed by this "use".

                                property method

                                method: string;
                                • Method used by this "use".

                                property priority

                                priority: number;
                                • Interceptor priority. Used for global interceptors.

                                property target

                                target: Function;
                                • Object class of the interceptor class.

                                class InternalServerError

                                class InternalServerError extends HttpError {}
                                • Exception for 500 HTTP error.

                                constructor

                                constructor(message: string);

                                  property name

                                  name: string;

                                    class KoaDriver

                                    class KoaDriver extends BaseDriver {}
                                    • Integration with koa framework.

                                    constructor

                                    constructor(koa?: any, router?: any);

                                      property koa

                                      koa?: any;

                                        property router

                                        router?: any;

                                          method getParamFromRequest

                                          getParamFromRequest: (actionOptions: Action, param: ParamMetadata) => any;
                                          • Gets param from the request.

                                          method handleError

                                          handleError: (
                                          error: any,
                                          action: ActionMetadata | undefined,
                                          options: Action
                                          ) => Promise<unknown>;
                                          • Handles result of failed executed controller action.

                                          method handleSuccess

                                          handleSuccess: (result: any, action: ActionMetadata, options: Action) => void;
                                          • Handles result of successfully executed controller action.

                                          method initialize

                                          initialize: () => void;
                                          • Initializes the things driver needs before routes and middleware registration.

                                          method loadKoa

                                          protected loadKoa: () => void;
                                          • Dynamically loads koa and required koa-router module.

                                          method prepareMiddlewares

                                          protected prepareMiddlewares: (uses: UseMetadata[]) => Function[];
                                          • Creates middlewares from the given "use"-s.

                                          method registerAction

                                          registerAction: (
                                          actionMetadata: ActionMetadata,
                                          executeCallback: (options: Action) => any
                                          ) => void;
                                          • Registers action in the driver.

                                          method registerMiddleware

                                          registerMiddleware: (middleware: MiddlewareMetadata) => void;
                                          • Registers middleware that run before controller actions.

                                          method registerRoutes

                                          registerRoutes: () => void;
                                          • Registers all routes in the framework.

                                          class MetadataArgsStorage

                                          class MetadataArgsStorage {}
                                          • Storage all metadatas read from decorators.

                                          property actions

                                          actions: ActionMetadataArgs[];
                                          • Registered action metadata args.

                                          property controllers

                                          controllers: ControllerMetadataArgs[];
                                          • Registered controller metadata args.

                                          property interceptors

                                          interceptors: InterceptorMetadataArgs[];
                                          • Registered interceptor metadata args.

                                          property middlewares

                                          middlewares: MiddlewareMetadataArgs[];
                                          • Registered middleware metadata args.

                                          property params

                                          params: ParamMetadataArgs[];
                                          • Registered param metadata args.

                                          property responseHandlers

                                          responseHandlers: ResponseHandlerMetadataArgs[];
                                          • Registered response handler metadata args.

                                          property useInterceptors

                                          useInterceptors: UseInterceptorMetadataArgs[];
                                          • Registered "use interceptor" metadata args.

                                          property uses

                                          uses: UseMetadataArgs[];
                                          • Registered "use middleware" metadata args.

                                          method filterActionsWithTarget

                                          filterActionsWithTarget: (target: Function) => ActionMetadataArgs[];
                                          • Filters registered actions by a given classes.

                                          method filterControllerMetadatasForClasses

                                          filterControllerMetadatasForClasses: (
                                          classes: Function[]
                                          ) => ControllerMetadataArgs[];
                                          • Filters registered controllers by a given classes.

                                          method filterInterceptorMetadatasForClasses

                                          filterInterceptorMetadatasForClasses: (
                                          classes: Function[]
                                          ) => InterceptorMetadataArgs[];
                                          • Filters registered interceptors by a given classes.

                                          method filterInterceptorUsesWithTargetAndMethod

                                          filterInterceptorUsesWithTargetAndMethod: (
                                          target: Function,
                                          methodName: string
                                          ) => UseInterceptorMetadataArgs[];
                                          • Filters registered "use interceptors" by a given target class and method name.

                                          method filterMiddlewareMetadatasForClasses

                                          filterMiddlewareMetadatasForClasses: (
                                          classes: Function[]
                                          ) => MiddlewareMetadataArgs[];
                                          • Filters registered middlewares by a given classes.

                                          method filterParamsWithTargetAndMethod

                                          filterParamsWithTargetAndMethod: (
                                          target: Function,
                                          methodName: string
                                          ) => ParamMetadataArgs[];
                                          • Filters parameters by a given classes.

                                          method filterResponseHandlersWithTarget

                                          filterResponseHandlersWithTarget: (
                                          target: Function
                                          ) => ResponseHandlerMetadataArgs[];
                                          • Filters response handlers by a given class.

                                          method filterResponseHandlersWithTargetAndMethod

                                          filterResponseHandlersWithTargetAndMethod: (
                                          target: Function,
                                          methodName: string
                                          ) => ResponseHandlerMetadataArgs[];
                                          • Filters response handlers by a given classes.

                                          method filterUsesWithTargetAndMethod

                                          filterUsesWithTargetAndMethod: (
                                          target: Function,
                                          methodName: string
                                          ) => UseMetadataArgs[];
                                          • Filters registered "use middlewares" by a given target class and method name.

                                          method reset

                                          reset: () => void;
                                          • Removes all saved metadata.

                                          class MethodNotAllowedError

                                          class MethodNotAllowedError extends HttpError {}
                                          • Exception for todo HTTP error.

                                          constructor

                                          constructor(message?: string);

                                            property name

                                            name: string;

                                              class MiddlewareMetadata

                                              class MiddlewareMetadata {}
                                              • Middleware metadata.

                                              constructor

                                              constructor(args: MiddlewareMetadataArgs);

                                                property global

                                                global: boolean;
                                                • Indicates if this middleware is global, thous applied to all routes.

                                                property instance

                                                readonly instance:
                                                | ExpressMiddlewareInterface
                                                | KoaMiddlewareInterface
                                                | ExpressErrorMiddlewareInterface;
                                                • Gets middleware instance from the container.

                                                property priority

                                                priority: number;
                                                • Execution priority of the middleware.

                                                property target

                                                target: Function;
                                                • Object class of the middleware class.

                                                property type

                                                type: 'before' | 'after';
                                                • Indicates if middleware must be executed after routing action is executed.

                                                class NotAcceptableError

                                                class NotAcceptableError extends HttpError {}
                                                • Exception for 406 HTTP error.

                                                constructor

                                                constructor(message?: string);

                                                  property name

                                                  name: string;

                                                    class NotFoundError

                                                    class NotFoundError extends HttpError {}
                                                    • Exception for 404 HTTP error.

                                                    constructor

                                                    constructor(message?: string);

                                                      property name

                                                      name: string;

                                                        class ParamMetadata

                                                        class ParamMetadata {}
                                                        • Action Parameter metadata.

                                                        constructor

                                                        constructor(actionMetadata: ActionMetadata, args: ParamMetadataArgs);

                                                          property actionMetadata

                                                          actionMetadata: ActionMetadata;
                                                          • Parameter's action.

                                                          property classTransform

                                                          classTransform?: any;
                                                          • Class transform options used to perform plainToClass operation.

                                                          property extraOptions

                                                          extraOptions: any;
                                                          • Additional parameter options. For example it can be uploader middleware options or body-parser middleware options.

                                                          property index

                                                          index: number;
                                                          • Index (# number) of the parameter in the method signature.

                                                          property isTargetObject

                                                          isTargetObject: boolean;
                                                          • Indicates if target type is an object.

                                                          property method

                                                          method: string;
                                                          • Method on which's parameter is attached.

                                                          property name

                                                          name: string;
                                                          • Parameter name.

                                                          property object

                                                          object: any;
                                                          • Object on which's method's parameter this parameter is attached.

                                                          property parse

                                                          parse: boolean;
                                                          • Specifies if parameter should be parsed as json or not.

                                                          property required

                                                          required: boolean;
                                                          • Indicates if this parameter is required or not

                                                          property target

                                                          target: any;
                                                          • Parameter target.

                                                          property targetName

                                                          targetName: string;
                                                          • Parameter target type's name in lowercase.

                                                          property targetType

                                                          targetType?: any;
                                                          • Parameter target type.

                                                          property transform

                                                          transform: (action: Action, value?: any) => Promise<any> | any;
                                                          • Transforms the value.

                                                          property type

                                                          type: ParamType;
                                                          • Parameter type.

                                                          property validate

                                                          validate?: any;
                                                          • If true, class-validator will be used to validate param object. If validation options are given then it means validation will be applied (is true).

                                                          class ResponseHandlerMetadata

                                                          class ResponseHandlerMetadata {}
                                                          • Response handler metadata.

                                                          constructor

                                                          constructor(args: ResponseHandlerMetadataArgs);

                                                            property method

                                                            method: string;
                                                            • Method on which decorator is set.

                                                            property secondaryValue

                                                            secondaryValue: any;
                                                            • Secondary property value. Can be header value for example.

                                                            property target

                                                            target: Function;
                                                            • Class on which's method decorator is set.

                                                            property type

                                                            type: ResponseHandlerType;
                                                            • Property type. See ResponsePropertyMetadataType for possible values.

                                                            property value

                                                            value: any;
                                                            • Property value. Can be status code, content-type, header name, template name, etc.

                                                            class UnauthorizedError

                                                            class UnauthorizedError extends HttpError {}
                                                            • Exception for 401 HTTP error.

                                                            constructor

                                                            constructor(message?: string);

                                                              property name

                                                              name: string;

                                                                class UseMetadata

                                                                class UseMetadata {}
                                                                • "Use middleware" metadata.

                                                                constructor

                                                                constructor(args: UseMetadataArgs);

                                                                  property afterAction

                                                                  afterAction: boolean;
                                                                  • Indicates if middleware must be executed after routing action is executed.

                                                                  property method

                                                                  method: string;
                                                                  • Method used by this "use".

                                                                  property middleware

                                                                  middleware: Function;
                                                                  • Middleware to be executed by this "use".

                                                                  property target

                                                                  target: Function;
                                                                  • Object class of the middleware class.

                                                                  Interfaces

                                                                  interface Action

                                                                  interface Action {}
                                                                  • Controller action properties.

                                                                  property context

                                                                  context?: any;
                                                                  • Content in which action is executed. Koa-specific property.

                                                                  property next

                                                                  next?: Function;
                                                                  • "Next" function used to call next middleware.

                                                                  property request

                                                                  request: any;
                                                                  • Action Request object.

                                                                  property response

                                                                  response: any;
                                                                  • Action Response object.

                                                                  interface BodyOptions

                                                                  interface BodyOptions {}
                                                                  • Body decorator parameters.

                                                                  property options

                                                                  options?: any;
                                                                  • Extra options to be passed to body-parser middleware.

                                                                  property required

                                                                  required?: boolean;
                                                                  • If set to true then request body will become required. If user performs a request and body is not in a request then routing-controllers will throw an error.

                                                                  property transform

                                                                  transform?: ClassTransformOptions;
                                                                  • Class-transformer options used to perform plainToClass operation.

                                                                    See Also

                                                                    • https://github.com/pleerock/class-transformer

                                                                  property type

                                                                  type?: any;
                                                                  • Explicitly set type which should be used for Body to perform transformation.

                                                                  property validate

                                                                  validate?: boolean | ValidatorOptions;
                                                                  • If true, class-validator will be used to validate param object. If validation options are given then class-validator will perform validation with given options.

                                                                    See Also

                                                                    • https://github.com/pleerock/class-validator

                                                                  interface CustomParameterDecorator

                                                                  interface CustomParameterDecorator {}
                                                                  • Used to register custom parameter handler in the controller action parameters.

                                                                  property required

                                                                  required?: boolean;
                                                                  • Indicates if this parameter is required or not. If parameter is required and value provided by it is not set then routing-controllers will throw an error.

                                                                  property value

                                                                  value: (action: Action, value?: any) => Promise<any> | any;
                                                                  • Factory function that returns value to be written to this parameter. In function it provides you Action object which contains current request, response, context objects. It also provides you original value of this parameter. It can return promise, and if it returns promise then promise will be resolved before calling controller action.

                                                                  interface ExpressErrorMiddlewareInterface

                                                                  interface ExpressErrorMiddlewareInterface {}
                                                                  • Express error middlewares can implement this interface.

                                                                  method error

                                                                  error: (
                                                                  error: any,
                                                                  request: any,
                                                                  response: any,
                                                                  next: (err?: any) => any
                                                                  ) => void;
                                                                  • Called before response.send is being called. The data passed to method is the data passed to .send method. Note that you must return same (or changed) data and it will be passed to .send method.

                                                                  interface ExpressMiddlewareInterface

                                                                  interface ExpressMiddlewareInterface {}
                                                                  • Used to register middlewares. This signature is used for express middlewares.

                                                                  method use

                                                                  use: (request: any, response: any, next: (err?: any) => any) => any;
                                                                  • Called before controller action is being executed. This signature is used for Express Middlewares.

                                                                  interface InterceptorInterface

                                                                  interface InterceptorInterface {}
                                                                  • Classes that intercepts response result must implement this interface.

                                                                  method intercept

                                                                  intercept: (action: Action, result: any) => any | Promise<any>;
                                                                  • Called before success response is being sent to the request. Returned result will be sent to the user.

                                                                  interface IocAdapter

                                                                  interface IocAdapter {}
                                                                  • Allows routing controllers to resolve objects using your IoC container

                                                                  method get

                                                                  get: <T>(someClass: ClassConstructor<T>, action?: Action) => T;
                                                                  • Return

                                                                  interface KoaMiddlewareInterface

                                                                  interface KoaMiddlewareInterface {}
                                                                  • Used to register middlewares. This signature is used for koa middlewares.

                                                                  method use

                                                                  use: (context: any, next: (err?: any) => Promise<any>) => Promise<any>;
                                                                  • Called before controller action is being executed.

                                                                  interface ParamOptions

                                                                  interface ParamOptions {}
                                                                  • Extra options set to the parameter decorators.

                                                                  property parse

                                                                  parse?: boolean;
                                                                  • If set to true then parameter will be parsed to json. Parsing is automatically done if parameter type is a class type.

                                                                  property required

                                                                  required?: boolean;
                                                                  • If set to true then parameter will be required. If user performs a request and required parameter is not in a request then routing-controllers will throw an error.

                                                                  property transform

                                                                  transform?: ClassTransformOptions;
                                                                  • Class transform options used to perform plainToClass operation.

                                                                  property type

                                                                  type?: any;
                                                                  • Explicitly set type which should be used for param to perform transformation.

                                                                  property validate

                                                                  validate?: boolean | ValidatorOptions;
                                                                  • If true, class-validator will be used to validate param object. If validation options are given then class-validator will perform validation with given options.

                                                                  interface RoleChecker

                                                                  interface RoleChecker {}

                                                                    method check

                                                                    check: (action: Action) => boolean | Promise<boolean>;

                                                                      interface RoutingControllersOptions

                                                                      interface RoutingControllersOptions {}
                                                                      • Routing controller initialization options.

                                                                      property authorizationChecker

                                                                      authorizationChecker?: AuthorizationChecker;
                                                                      • Special function used to check user authorization roles per request. Must return true or promise with boolean true resolved for authorization to succeed.

                                                                      property classToPlainTransformOptions

                                                                      classToPlainTransformOptions?: ClassTransformOptions;
                                                                      • Global class transformer options passed to class-transformer during classToPlain operation. This operation is being executed when server returns response to user.

                                                                      property classTransformer

                                                                      classTransformer?: boolean;
                                                                      • Indicates if class-transformer should be used to perform serialization / deserialization.

                                                                      property controllers

                                                                      controllers?: Function[] | string[];
                                                                      • List of controllers to register in the framework or directories from where to import all your controllers.

                                                                      property cors

                                                                      cors?: boolean | Object;
                                                                      • Indicates if cors are enabled. This requires installation of additional module (cors for express and kcors for koa).

                                                                      property currentUserChecker

                                                                      currentUserChecker?: CurrentUserChecker;
                                                                      • Special function used to get currently authorized user.

                                                                      property defaultErrorHandler

                                                                      defaultErrorHandler?: boolean;
                                                                      • Indicates if default routing-controller's error handler is enabled or not. Enabled by default.

                                                                      property defaults

                                                                      defaults?: {
                                                                      /**
                                                                      * If set, all null responses will return specified status code by default
                                                                      */
                                                                      nullResultCode?: number;
                                                                      /**
                                                                      * If set, all undefined responses will return specified status code by default
                                                                      */
                                                                      undefinedResultCode?: number;
                                                                      /**
                                                                      * Default param options
                                                                      */
                                                                      paramOptions?: {
                                                                      /**
                                                                      * If true, all non-set parameters will be required by default
                                                                      */
                                                                      required?: boolean;
                                                                      };
                                                                      };
                                                                      • Default settings

                                                                      property development

                                                                      development?: boolean;
                                                                      • Indicates if development mode is enabled. By default its enabled if your NODE_ENV is not equal to "production".

                                                                      property errorOverridingMap

                                                                      errorOverridingMap?: {
                                                                      [key: string]: any;
                                                                      };
                                                                      • Map of error overrides.

                                                                      property interceptors

                                                                      interceptors?: Function[] | string[];
                                                                      • List of interceptors to register in the framework or directories from where to import all your interceptors.

                                                                      property middlewares

                                                                      middlewares?: Function[] | string[];
                                                                      • List of middlewares to register in the framework or directories from where to import all your middlewares.

                                                                      property plainToClassTransformOptions

                                                                      plainToClassTransformOptions?: ClassTransformOptions;
                                                                      • Global class transformer options passed to class-transformer during plainToClass operation. This operation is being executed when parsing user parameters.

                                                                      property routePrefix

                                                                      routePrefix?: string;
                                                                      • Global route prefix, for example '/api'.

                                                                      property validation

                                                                      validation?: boolean | ValidatorOptions;
                                                                      • Indicates if class-validator should be used to auto validate objects injected into params. You can also directly pass validator options to enable validator with a given options.

                                                                      interface UploadOptions

                                                                      interface UploadOptions {}
                                                                      • Upload decorator parameters.

                                                                      property options

                                                                      options?: any;
                                                                      • Special upload options passed to an upload middleware.

                                                                      property required

                                                                      required?: boolean;
                                                                      • If set to true then uploaded file become required. If user performs a request and file is not in a request then routing-controllers will throw an error.

                                                                      interface UseContainerOptions

                                                                      interface UseContainerOptions {}
                                                                      • Container options.

                                                                      property fallback

                                                                      fallback?: boolean;
                                                                      • If set to true, then default container will be used in the case if given container haven't returned anything.

                                                                      property fallbackOnErrors

                                                                      fallbackOnErrors?: boolean;
                                                                      • If set to true, then default container will be used in the case if given container thrown an exception.

                                                                      Type Aliases

                                                                      type ClassConstructor

                                                                      type ClassConstructor<T> = {
                                                                      new (...args: any[]): T;
                                                                      };

                                                                        Package Files (76)

                                                                        Dependencies (12)

                                                                        Dev Dependencies (0)

                                                                        No dev dependencies.

                                                                        Peer Dependencies (2)

                                                                        Badge

                                                                        To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                        You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/routing-controllers.

                                                                        • Markdown
                                                                          [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/routing-controllers)
                                                                        • HTML
                                                                          <a href="https://www.jsdocs.io/package/routing-controllers"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>