@tekbox/rest-express
TypeScript icon, indicating that this package has built-in type declarations

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

Dependencies (17)

Dev Dependencies (12)

Package Sidebar

Install

npm i @tekbox/rest-express

Weekly Downloads

0

Version

0.1.17

License

none

Unpacked Size

93.8 kB

Total Files

76

Last publish

Collaborators

  • r1co