API Response Formatter
Response Formatter provides a consistent, type-safe response structure for NestJS APIs.
Installation Guide
Run the following command:
npx servercn-cli@latest add response-formatter Register the interceptor and filter
Register the interceptor and exception filter globally in your root module or bootstrap file.
Option 1: Global Setup (Recommended)
Option 2: Per-Module Setup
Usage Examples
1. Basic Success Response
Return data directly from your controller — the interceptor handles wrapping:
Response:
2. Custom Message with Decorator
Response:
3. Manual ApiResponse (Bypass Interceptor)
Return an ApiResponse instance directly to skip automatic wrapping:
Response:
4. Error Handling
Throw standard NestJS exceptions — the filter handles formatting:
Response:
5. Pagination with Meta
Response: