Middlewares
A middleware class will run before the action of the controller invoked.
Class Middleware#
The middleware class must extend Middleware and implement the run method.
if run return a promise next will be called automatically.
new middleware instance will be created or each request.
The middleware must implement one of the following methods:
- run - if its regular middleware
- error - if its error middleware
- runWithData - if its data middleware
now you can add the middleware to our route
static middlewares supported same as static controllers and will be created once
Express Middleware#
you can also use any express or custom middleware functions
Controller Middleware#
when a middleware added on a controller it will be applied on all controller actions
Global Middlewares#
The middlewares will be used on all requests.
API#
sendError#
sendError(error?: Error | string, code?: number, data?: any)#
send response error with status 500
sendBadRequest#
sendBadRequest(error?: Error | string, code?: number, data?: any)#
send response error BadRequestError with status 400
sendUnauthorized#
sendUnauthorized(error?: Error | string, code?: number, data?: any)#
send response error UnauthorizedError with status 401
sendNotFound#
sendNotFound(error?: Error | string, code?: number, data?: any)#
send response error NotFoundError with status 404
getModel#
getModel(): T#
return combined object of req.query, req.body and req.params