@fromnibly/hallpass
TypeScript icon, indicating that this package has built-in type declarations

0.3.0 • Public • Published

hallpass

hallpass is a class based express router wiring for nodejs written in typescript.

Getting Started

First lets show a very simple example of a class with a get request.

import { Method, Path } from '@fromnibly/hallpass';
export class HelloWorldHandler {
  @Method('get')
  @Path('/hello')
  handleGetHello(req: Request, res: Response): void {
    req.status(202).send('Hello World');
  }
}

The equivilent of this using bare express would be

import * as express from 'express';
export function initApp(app: express.Application) {
  app.get('/hello', (req: Request, res: Response) => {
    req.status(200).send('Hello World');
  });
}

wiring it up

Once you have created all of your classes you will need to wire them up to your router.

import * as express from 'express';

let server = express();

let classRouter = new ClassRouter(server);

classRouter.registerRouteHandler(new HelloWorldHandler());

classRouter.initializeRoutes();

server.listen(8080, () => {
  console.log('server started on port 8080');
});

One important thing to note is that the registerRouteHandler function takes an instantiated class. This means that the construction can be left up to something else like a dependency injection framework like inversify. The only requirement of a given class is that it has a constructor with a name.

more in depth information in the wiki

Package Sidebar

Install

npm i @fromnibly/hallpass

Weekly Downloads

1

Version

0.3.0

License

MIT

Unpacked Size

45 kB

Total Files

71

Last publish

Collaborators

  • from-nibly