Optional
Rest
...middlewares: HttpMiddleware[]One or more middleware to add.
The new decorator function.
import { Controller, ControllerBase, IHttpRequest, IHttpResponse, json, PATCH, POST, schema, Use, validate } from '@egomobile/http-server'
const fooSchema = schema.object({
// schema definition for /foo
})
const barSchema = schema.object({
// schema definition for /bar
})
@Controller()
@Use(json())
export default class MyController extends ControllerBase {
@POST({
use: [validate(fooSchema)] // additional, method specific middleware
})
async foo(request: IHttpRequest, response: IHttpResponse) {
// request.body should now be a plain object
// created from JSON string input
// and validated with fooSchema
}
@PATCH({
use: [validate(barSchema)]
})
async bar(request: IHttpRequest, response: IHttpResponse) {
// request.body should now also be a plain object
// created from JSON string input
// and validated with barSchema
}
}
Generated using TypeDoc
Sets up one or more middlewares for all methods of the underlying controller.