APIs for NestJSs
NestJS API tooling covers exposing your service in documented, typed forms. @nestjs/swagger generates an OpenAPI specification from decorators for REST, while @nestjs/graphql builds a GraphQL schema using code-first or schema-first approaches with resolvers instead of controllers.
Stage: Integrations · Part of the NestJS roadmap · Last reviewed 19 November 2026
What to learn in APIs
- Generate an OpenAPI document with SwaggerModule and decorators like @ApiProperty
- Write a GraphQL resolver with @Query and @Mutation
- Choose between code-first and schema-first GraphQL
- Validate request bodies using class-validator with ValidationPipe
- Version a REST API using URI or header versioning
APIs interview questions
What is the difference between code-first and schema-first GraphQL in NestJS?
In code-first, you write TypeScript classes with decorators and Nest generates the SDL schema. In schema-first, you write the .graphql schema yourself and Nest generates TypeScript types from it. Code-first avoids duplicating definitions.
How does ValidationPipe work?
ValidationPipe takes the incoming payload, transforms it into the DTO class with class-transformer and checks the class-validator decorators. If validation fails, it throws a 400 BadRequestException with the list of errors before the handler runs.
Where APIs fits in the NestJS roadmap
APIs belongs to the Integrations stage (intermediate level). Beyond HTTP.
Other units in this stage
Back to the full NestJS roadmap