codeburst

Bursts of code to power through your day. Web Development articles, tutorials, and news.

Follow publication

Integrating Swagger with NestJS

A step-by-step guide to generating OpenAPI documentation for your RESTful API

Nick McHenry
codeburst
Published in
6 min readSep 2, 2020

--

Photo by Emile Perron on Unsplash

In this article, we will integrate Swagger with a RESTful API built using NestJS. As a quick refresher, NestJS is a server-side web framework that supports both TypeScript and JavaScript. It brings an opinionated architecture to building a Node.js backend that is inspired by the Angular ecosystem. For more information, check out this introduction to NestJS.

On the other hand, Swagger is a tool for implementing the OpenAPI specification. The goal of the OpenAPI specification is to provide a standardized way to understand the capabilities of an API service without actual access to the source code. On the whole, Swagger is a tremendously helpful documentation tool for any modern web backend that exposes a RESTful API. More than just documentation, the OpenAPI specification served up by Swagger can be used to autogenerate servers/clients, facilitate automated testing, and much more.

In the following sections, we’ll add Swagger to a basic RESTful API built using NestJS.

Initial Setup

The first dependency that we’ll need is the NestJS CLI. Go ahead and install it globally by running npm install -g @nestjs/cli. Once this is in place, bootstrap a new NestJS project using the CLI command nest new nestjs-with-swagger. At this point, we should have a boilerplate NestJS project setup with a module, controller, and service.

We’ll now create a simple task tracking application by adding a new module for handling tasks and a few other files, as shown below:

--

--

Published in codeburst

Bursts of code to power through your day. Web Development articles, tutorials, and news.

Written by Nick McHenry

Software Developer and Architect. I write about software engineering and up-and-coming technology. Become a Medium member https://bit.ly/3FEQ1Zd

Responses (4)

Write a response