1.3.0 • Published 3 months ago

nestjs-asyncapi v1.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

Description

AsyncApi module for Nest.

Generate AsyncApi documentation (for event-based services, like websockets) in a similar to nestjs/swagger fashion.

Documentation example

Installation

full installation (with chromium)

$ npm i --save nestjs-asyncapi

nestjs-async api package doesn't require chromium (which is required by asyncapi lib), so u can skip chromium installation by setting PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true environment variable.

$ PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true npm i --save nestjs-asyncapi

Quick Start

Include AsyncApi initialization into your bootstrap function.

async function bootstrap() {
    const app = await NestFactory.create<NestExpressApplication>(AppModule);

    const asyncApiOptions = new AsyncApiDocumentBuilder()
        .setTitle('Feline')
        .setDescription('Feline server description here')
        .setVersion('1.0')
        .setDefaultContentType('application/json')
        .addSecurity('user-password', {type: 'userPassword'})
        .addServer('feline-ws', {
            url: 'ws://localhost:3000',
            protocol: 'socket.io',
        })
        .build();

    const asyncapiDocument = await AsyncApiModule.createDocument(app, asyncApiOptions);
    await AsyncApiModule.setup(docRelPath, app, asyncapiDocument);

    // other bootstrap procedures here

    return app.listen(3000);
}

AsyncApi module explores Controllers & WebSocketGateway by default. In most cases you won't need to add extra annotation, but if you need to define asyncApi operations in a class that's not a controller or gateway use the AsyncApi class decorator.

Mark pub/sub methods via AsyncApiPub or AsyncApiSub decorators

class CreateFelineDto {
    @ApiProperty()
    demo: string;
}

@Controller()
class DemoController {
    @AsyncApiPub({
        channel: 'create/feline',
        message: {
            payload: CreateFelineDto
        },
    })
    async createFeline() {
        // logic here
    }

    @AsyncApiSub({
        channel: 'create/feline',
        message: {
            payload: CreateFelineDto
        },
    })
    async createFeline() {
        // logic here
    }
}

For more detailed examples please check out https://github.com/flamewow/nestjs-asyncapi/tree/main/sample sample app.

1.2.3

3 months ago

1.3.0

3 months ago

1.2.2

3 months ago

1.2.0

10 months ago

1.2.1

10 months ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.2.0-beta

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

0.3.6

1 year ago

0.3.5

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.4

2 years ago

0.3.3

2 years ago

0.2.12

2 years ago

0.2.11

2 years ago

0.3.0

2 years ago

0.2.10

2 years ago

0.2.7

2 years ago

0.2.6

2 years ago

0.2.9

2 years ago

0.2.8

2 years ago

0.2.5

2 years ago

0.2.3

2 years ago

0.2.4

2 years ago

0.2.2

2 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.4

3 years ago

0.1.0

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.3

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago