routing-controllers
- Version 0.11.0
- Published
- 950 kB
- 4 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
- All()
- Authorized()
- Body()
- BodyParam()
- ContentType()
- Controller()
- CookieParam()
- CookieParams()
- createExecutor()
- createExpressServer()
- createKoaServer()
- createParamDecorator()
- createServer()
- Ctx()
- CurrentUser()
- Delete()
- Get()
- getFromContainer()
- getMetadataArgsStorage()
- Head()
- Header()
- HeaderParam()
- HeaderParams()
- HttpCode()
- Interceptor()
- JsonController()
- Location()
- Method()
- Middleware()
- OnNull()
- OnUndefined()
- Param()
- Params()
- Patch()
- Post()
- Put()
- QueryParam()
- QueryParams()
- Redirect()
- Render()
- Req()
- Res()
- ResponseClassTransformOptions()
- Session()
- SessionParam()
- State()
- UploadedFile()
- UploadedFiles()
- UseAfter()
- UseBefore()
- useContainer()
- useExpressServer()
- UseInterceptor()
- useKoaServer()
Classes
ActionMetadata
- appendBaseRoute()
- appendParams
- authorizedRoles
- bodyExtraOptions
- build()
- callMethod()
- controllerMetadata
- fullRoute
- headers
- interceptors
- isAuthorizedUsed
- isBodyUsed
- isFilesUsed
- isFileUsed
- isJsonTyped
- method
- methodOverride
- nullResultCode
- options
- params
- redirect
- renderedTemplate
- responseClassTransformOptions
- route
- successHttpCode
- target
- type
- undefinedResultCode
- uses
BaseDriver
- app
- authorizationChecker
- classToPlainTransformOptions
- cors
- currentUserChecker
- developmentMode
- enableValidation
- errorOverridingMap
- getParamFromRequest()
- handleError()
- handleSuccess()
- initialize()
- isDefaultErrorHandlingEnabled
- merge()
- plainToClassTransformOptions
- processJsonError()
- processTextError()
- registerAction()
- registerMiddleware()
- registerRoutes()
- routePrefix
- transformResult()
- useClassTransformer
- validationOptions
MetadataArgsStorage
- actions
- controllers
- filterActionsWithTarget()
- filterControllerMetadatasForClasses()
- filterInterceptorMetadatasForClasses()
- filterInterceptorUsesWithTargetAndMethod()
- filterMiddlewareMetadatasForClasses()
- filterParamsWithTargetAndMethod()
- filterResponseHandlersWithTarget()
- filterResponseHandlersWithTargetAndMethod()
- filterUsesWithTargetAndMethod()
- interceptors
- middlewares
- params
- reset()
- responseHandlers
- useInterceptors
- uses
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.
function Head
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.
function Header
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.
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: ClassTransformOptions) => 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: ClassTransformOptions;
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: ClassTransformOptions;
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 @koa/cors 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: 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 application prefix.
property useClassTransformer
useClassTransformer: boolean;
Indicates if class-transformer should be used or not.
property validationOptions
validationOptions: ValidatorOptions;
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, options: RoutingControllersOptions) => 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, options: RoutingControllersOptions) => 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<void>;
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 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?: ClassTransformOptions;
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 isArray
isArray?: boolean;
If true, string values are cast to arrays
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 UnprocessableEntityError
class UnprocessableEntityError extends HttpError {}
Exception for 422 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.
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/typestack/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/typestack/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 isArray
isArray?: boolean;
Force value to be cast as an array.
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 @koa/cors 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.
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 AuthorizationChecker
type AuthorizationChecker = ( action: Action, roles: any[]) => Promise<boolean> | boolean;
Special function used to check user authorization roles per request. Must return true or promise with boolean true resolved for authorization to succeed.
type ClassConstructor
type ClassConstructor<T> = { new (...args: any[]): T;};
type CurrentUserChecker
type CurrentUserChecker = <User = any>( action: Action) => Promise<User | null> | User | null;
Special function used to get currently authorized user.
Package Files (79)
- types/Action.d.ts
- types/AuthorizationChecker.d.ts
- types/CurrentUserChecker.d.ts
- types/CustomParameterDecorator.d.ts
- types/InterceptorInterface.d.ts
- types/RoleChecker.d.ts
- types/RoutingControllersOptions.d.ts
- types/container.d.ts
- types/decorator-options/BodyOptions.d.ts
- types/decorator-options/ParamOptions.d.ts
- types/decorator-options/UploadOptions.d.ts
- types/decorator/All.d.ts
- types/decorator/Authorized.d.ts
- types/decorator/Body.d.ts
- types/decorator/BodyParam.d.ts
- types/decorator/ContentType.d.ts
- types/decorator/Controller.d.ts
- types/decorator/CookieParam.d.ts
- types/decorator/CookieParams.d.ts
- types/decorator/Ctx.d.ts
- types/decorator/CurrentUser.d.ts
- types/decorator/Delete.d.ts
- types/decorator/Get.d.ts
- types/decorator/Head.d.ts
- types/decorator/Header.d.ts
- types/decorator/HeaderParam.d.ts
- types/decorator/HeaderParams.d.ts
- types/decorator/HttpCode.d.ts
- types/decorator/Interceptor.d.ts
- types/decorator/JsonController.d.ts
- types/decorator/Location.d.ts
- types/decorator/Method.d.ts
- types/decorator/Middleware.d.ts
- types/decorator/OnNull.d.ts
- types/decorator/OnUndefined.d.ts
- types/decorator/Param.d.ts
- types/decorator/Params.d.ts
- types/decorator/Patch.d.ts
- types/decorator/Post.d.ts
- types/decorator/Put.d.ts
- types/decorator/QueryParam.d.ts
- types/decorator/QueryParams.d.ts
- types/decorator/Redirect.d.ts
- types/decorator/Render.d.ts
- types/decorator/Req.d.ts
- types/decorator/Res.d.ts
- types/decorator/ResponseClassTransformOptions.d.ts
- types/decorator/Session.d.ts
- types/decorator/SessionParam.d.ts
- types/decorator/State.d.ts
- types/decorator/UploadedFile.d.ts
- types/decorator/UploadedFiles.d.ts
- types/decorator/UseAfter.d.ts
- types/decorator/UseBefore.d.ts
- types/decorator/UseInterceptor.d.ts
- types/driver/BaseDriver.d.ts
- types/driver/express/ExpressDriver.d.ts
- types/driver/express/ExpressErrorMiddlewareInterface.d.ts
- types/driver/express/ExpressMiddlewareInterface.d.ts
- types/driver/koa/KoaDriver.d.ts
- types/driver/koa/KoaMiddlewareInterface.d.ts
- types/http-error/BadRequestError.d.ts
- types/http-error/ForbiddenError.d.ts
- types/http-error/HttpError.d.ts
- types/http-error/InternalServerError.d.ts
- types/http-error/MethodNotAllowedError.d.ts
- types/http-error/NotAcceptableError.d.ts
- types/http-error/NotFoundError.d.ts
- types/http-error/UnauthorizedError.d.ts
- types/http-error/UnprocessableEntityError.d.ts
- types/index.d.ts
- types/metadata-builder/MetadataArgsStorage.d.ts
- types/metadata/ActionMetadata.d.ts
- types/metadata/ControllerMetadata.d.ts
- types/metadata/InterceptorMetadata.d.ts
- types/metadata/MiddlewareMetadata.d.ts
- types/metadata/ParamMetadata.d.ts
- types/metadata/ResponseHandleMetadata.d.ts
- types/metadata/UseMetadata.d.ts
Dependencies (4)
Dev Dependencies (0)
No dev dependencies.
Peer Dependencies (2)
Badge
To add a badge like this oneto 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[](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>
- Updated .
Package analyzed in 7168 ms. - Missing or incorrect documentation? Open an issue for this package.