41
loading...
This website collects cookies to deliver better user experience
description
of your swagger spec. How to do this will of course also vary depending on your stack, but in NestJS, a full swagger config sample might look like this (in main.ts
):const app = await NestFactory.create(AppModule);
// Swagger setup
const config = new DocumentBuilder()
.setTitle('My API')
.setDescription('My API specification')
.setVersion('1.0')
.addTag('app', '')
.setDescription('<a href="https://insomnia.rest/run/?label=My%20API&uri=http%3A%2F%2Flocalhost%3A3001%2Fapi-json" target="_blank"><img src="https://insomnia.rest/images/run.svg" alt="Run in Insomnia"></a>')
.build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('api', app, document);
await app.listen(3001);
baseUrl
) has been imported, contained within a folder as identified by the tag
in the swagger spec. This probably doesn’t look too impressive with just a single endpoint - but imagine a real application with half a dozen (or more) tags and dozens of endpoints. Being able to import the entire thing into your REST client with the click of a button sure is cool! And to top it all off, it’s not just any old REST client - it’s Insomnia! 😎