Member-only story
Generate, Package, and Publish: A TypeScript API Client for NestJS
Leveraging Swagger and OpenAPI to Generate a TypeScript Client for NestJS

Whether you’re developing a frontend application, a microservice, or a third-party integration, a well-structured TypeScript API client ensures type-safe, consistent, and efficient communication with your API.
Manually building an API client can be tedious and error-prone, which is why more projects are adopting auto-generated API clients for improved reliability and efficiency.
This tutorial will guide you through creating a TypeScript API client for a NestJS server. The process consists of three main steps:
- Generate an OpenAPI JSON file using the Swagger module in a NestJS app.
- Create TypeScript client files with the
swagger-typescript-api
library. - Package and publish the client as an npm module.
By the end, you’ll have a reusable TypeScript API client that can be easily shared and integrated into frontend applications or other services.
Generate OpenAPI JSON File Using Swagger in NestJS
First, install the @nestjs/swagger
package in your NestJS project: