Nosferatu's Pace Maker

    @ichainml/hapi-decorators
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.5 • Public • Published

    hapi-decorators

    npm version

    npm install @ichainml/hapi-decorators

    usage

    import {
      Controller,
      Get,
      Post,
      ServerSettings,
      ServerLoader,
      Api
    } from '@ichainml/hapi-decorators';
    import { Request, ResponseToolkit } from 'hapi';
    
    @ServerSettings({
      port: 3000,
      host: '0.0.0.0'
    })
    class Server extends ServerLoader {
      // public async initPlugins() {
      //   // await this.server.register(inert);
      // }
      onServerStarted() {
        console.log(`server started at ${this.server.info.uri}`);
      }
    }
    
    /** for each controller, it must extend class ``Api`` */
    @Controller('/api/user')
    class UserApi extends Api {
      constructor(private id: string) {
        super();
      }
      @Get('')
      getUserById() {
        return this.id;
      }
    
      @Post('/{id}')
      updateUserId() {
        // todo
      }
    }
    
    @Controller('/api/vote')
    class Vote extends Api {
      @Get('/all')
      getAllVotes(req: Request, h: ResponseToolkit) {
        // ...
      }
      @Post('')
      addVote() {
        // ...
      }
    }
    
    /** all the endpoints must be instantiated before server start. */
    const user = new UserApi('test');
    const vote = new Vote();
    console.log(user, vote);
    const server = new Server();
    server.start();

    Keywords

    none

    Install

    npm i @ichainml/hapi-decorators

    DownloadsWeekly Downloads

    1

    Version

    1.0.5

    License

    MIT

    Unpacked Size

    22.7 kB

    Total Files

    14

    Last publish

    Collaborators

    • gitawego