Skip to content

gustoase/nestjs-ws-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@drozd/nestjs-ws-api

NPM version

  1. Turns a normal REST api into a websocket.
  2. Accelerates api by 10 times due to one open ws channel.
  3. Controllers also remain native swagger REST API.

Setup

npm install @drozd/nestjs-ws-api

or

yarn add @drozd/nestjs-ws-api

then inside your app.module.ts add config:

@Module({
  imports: [
    ConfigModule.forRoot(),
    WsModule.registerAsync({
      useFactory: (): IWsApiConfig => {
          return {
            validationConfig,
            async validate(socket: Socket) {
              console.log(new ExecutionContextHost([socket]));
              return HttpStatus.OK;
            },
          };
      },
    }),
  ],
})
export class AppModule {}

And more use in controllers

  @Get(':id')
  @WsAction('user')
  getUser(@Param('id', ParseIntPipe) id: number): UserDto {
    return this.appService.getUser(id);
  }

See full demo https://github.com/gustoase/nestjs-ws-api-demo

License

MIT

About

Wrapper REST api WebsocketActions

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published