Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

@tekbox/rest-express

0.1.17 • Public • Published

@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();

Keywords

none

install

npm i @tekbox/rest-express

Downloadsweekly downloads

22

version

0.1.17

license

none

last publish

collaborators

  • avatar