- Turns a normal REST api into a websocket.
- Accelerates api by 10 times due to one open ws channel.
- Controllers also remain native swagger REST API.
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
MIT