Agent-skills-standard nestjs-api-standards
Create standardized API response envelopes, paginated endpoints, and error interceptors in NestJS. Use when implementing response wrappers, pagination DTOs, or global error formats. (triggers: **/*.controller.ts, **/*.dto.ts, ApiResponse, Pagination, TransformInterceptor)
install
source · Clone the upstream repo
git clone https://github.com/HoangNguyen0403/agent-skills-standard
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/HoangNguyen0403/agent-skills-standard "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/nestjs/nestjs-api-standards" ~/.claude/skills/hoangnguyen0403-agent-skills-standard-nestjs-api-standards && rm -rf "$T"
manifest:
skills/nestjs/nestjs-api-standards/SKILL.mdsource content
NestJS API Standards & Common Patterns
Priority: P1 (OPERATIONAL)
Workflow: Standardize API Endpoint
- Create Response DTO — Define dedicated DTO for every endpoint return type.
- Map entity to DTO — Use
in service or controller.plainToInstance(UserResponseDto, user) - Apply TransformInterceptor — Bind globally to wrap all responses in
.{ statusCode, data, meta } - Add nested validation — Decorate nested DTO properties with
+@ValidateNested()
.@Type() - Document with Swagger — Apply
with exact types per endpoint.@ApiResponse({ status, type })
Response Wrapper Example
Entity-to-DTO Mapping Example
Deep Validation (Critical)
- [Rule] Nested Validation: Object/array DTO properties require
+@ValidateNested()
from@Type(() => TargetDto)
.class-transformer
Pagination Standards
- DTOs: Use strict
(page/take/order) andPageOptionsDto
(data/meta).PageDto<T> - Swagger Logic: Generics require
and schema path resolution.ApiExtraModels - Reference: See Pagination Wrapper Implementation for complete
decorator code.ApiPaginatedResponse
Custom Error Response
- Standard Error Object: Define
withApiErrorResponse
,statusCode
,message
,error
,timestamp
. See Error Response Class.path - Docs: Apply
globally or per controller.@ApiBadRequestResponse({ type: ApiErrorResponse })
Anti-Patterns
- No raw entity returns: Always map to Response DTO; raw entities leak internal fields.
- No unvalidated nested DTOs: Use
+@ValidateNested()
for all nested object properties.@Type() - No generic 200 docs: Apply
with exact types per endpoint.@ApiResponse({ status, type })