@tekbox/rest-express
v0.1.17
Published
Basic express server with decorators for simple routing.
Downloads
5
Readme
@tekbox/rest-express
Basic express server with decorators for simple routing.
Usage:
Define a route:
export class TestRoute extends BaseRoute {
@Route.GET("/")
test(req: express.Request, res: express.Response) {
res.send("GET: Hello World");
}
@Route.POST("/")
test1(req: express.Request, res: express.Response) {
res.send("POST: Hello World");
}
@Route.PUT("/")
test2(req: express.Request, res: express.Response) {
res.send("PUT: Hello World");
}
@Route.PATCH("/")
test3(req: express.Request, res: express.Response) {
res.send("PATCH: Hello World");
}
@Route.DELETE("/")
test4(req: express.Request, res: express.Response) {
res.send("DELETE: Hello World");
}
}
Define app and register routes:
export class TestApp extends AbstractExpressApp {
/*
* Register routes
*/
protected setupAdditionalFilterChain() {
const routes = [new CORSRoute(), new AuthRoute(), new BandRoute(), new AppRoute()];
this.filterChain.push(new RouterMiddleware(routes));
}
}
Start server:
const defaultServer = new DefaultServer(3000, new TestApp());
defaultServer.start();