-
Notifications
You must be signed in to change notification settings - Fork 107
@PreProcessor Decorator
Thiago Bustamante edited this page Jan 20, 2019
·
1 revision
It is possible to add a function to process the request before the handler on an endpoint by endpoint basis. This can be used to add a validator to your application without including it in the body of the handler.
function validator(req: express.Request): express.Request {
if (!req.body.userId) {
throw new Errors.BadRequestError("userId not present");
}
}
@Path('users')
export class UserHandler {
@Path('email')
@POST
@PreProcessor(validator)
setEmail(body: any) {
// will have body.userId
}
}
PreProcessors can also be added to a class, applying it to all endpoints on the class
@Path('users')
@PreProcessor(validator)
export class UserHandler {
@Path('email')
@POST
setEmail(body: any) {
// will have body.user
}
}
- Server
- @Path Decorator
- Http Methods
- Request Parameters
- Types and languages
- @BodyOptions Decorator
- Service Context
- Service Return
- @Security Decorator
- Express Middlewares
- @PreProcessor Decorator
- @PostProcessor Decorator
- Server Errors
- Service Factory and IoC
- Inheritance and Abstract Services
- Swagger Documentation