Accessing Swagger UI
The Swagger documentation is available at:Replace
localhost:3000 with your actual API host and port. The default port is 3000, but this can be configured via the PORT environment variable.Swagger JSON Specification
The raw OpenAPI JSON specification is available at:What’s Included
The Swagger documentation includes:Complete API Reference
- All endpoints: Auth and Price endpoints
- HTTP methods: GET, POST, etc.
- Request parameters: Path params, query params, request bodies
- Response schemas: Success and error response formats
- Authentication: Bearer token authentication setup
Interactive Features
- Try it out: Execute API requests directly from the browser
- Request/Response examples: Pre-filled example data for all endpoints
- Schema documentation: Detailed DTO and model definitions
- Authentication testing: Built-in authorization header management
Error Documentation
Each endpoint includes all possible HTTP status codes:200- Success responses400- Bad Request (validation errors)401- Unauthorized (authentication errors)404- Not Found (resource doesn’t exist)429- Too Many Requests (rate limit exceeded)502- Bad Gateway (upstream failure)503- Service Unavailable (Redis unavailable)504- Gateway Timeout (request timeout)
How to Use Swagger UI
Step 1: Access the Documentation
Open your browser and navigate to:Step 2: Authenticate
-
Get an access token:
- Expand the
POST /auth/loginendpoint - Click Try it out
- Enter your credentials in the request body:
- Click Execute
- Copy the
accessTokenfrom the response
- Expand the
-
Set up authentication:
- Click the Authorize button at the top right
- In the dialog, enter:
Bearer <your-access-token> - Click Authorize
- Click Close
Step 3: Test Endpoints
With authentication set up, you can now test protected endpoints:-
Get current price:
- Expand
GET /v1/price/{coinId} - Click Try it out
- Enter a coin ID (e.g.,
bitcoin) - Click Execute
- View the response below
- Expand
-
Get price history:
- Expand
GET /v1/price/{coinId}/history - Click Try it out
- Enter a coin ID and optional query parameters
- Click Execute
- View the paginated response
- Expand
Step 4: Explore Schemas
Scroll down to the Schemas section to see detailed documentation for:- Request DTOs (LoginDto, HistoryQueryDto)
- Response DTOs (PriceResponseDto, HistoryResponseDto, TokenResponseDto)
- Error responses (ErrorResponseDto)
API Overview in Swagger
The Swagger UI displays the following information from the API configuration: Title: Crypto Pulse API Description:Configuration
Swagger is configured insrc/main.ts using the following setup:
Decorators Used
The API uses Swagger decorators to document endpoints:@ApiTags()- Group endpoints by category@ApiOperation()- Describe endpoint purpose@ApiParam()- Document path parameters@ApiBody()- Document request body@ApiOkResponse()- Document success responses@ApiBadRequestResponse()- Document 400 errors@ApiUnauthorizedResponse()- Document 401 errors@ApiNotFoundResponse()- Document 404 errors@ApiTooManyRequestsResponse()- Document 429 errors@ApiServiceUnavailableResponse()- Document 503 errors@ApiGatewayTimeoutResponse()- Document 504 errors@ApiBearerAuth()- Mark endpoints as requiring authentication
Benefits of Swagger Documentation
For Developers
- No separate documentation: API docs are generated from code annotations
- Always up-to-date: Changes to controllers automatically update Swagger
- Type safety: Uses the same DTOs as the actual API
- Quick testing: No need for separate API testing tools during development
For API Consumers
- Interactive exploration: Try endpoints without writing code
- Clear examples: See exactly what data to send and expect
- Complete reference: All endpoints, parameters, and responses in one place
- Easy integration: Export OpenAPI spec for code generation
Rate Limiting
The Swagger documentation endpoints (
/docs and /docs-json) are excluded from rate limiting. You can access them freely without consuming your API quota.AppThrottlerGuard which checks the request path and bypasses rate limiting for documentation routes.
Example Response
When you executeGET /v1/price/bitcoin through Swagger, you’ll see:
- Response code: 200
- Response body: Formatted JSON with syntax highlighting
- Response headers: Content-Type, etc.
- Request duration: Time taken to execute the request
Troubleshooting
Cannot Access /docs
If you can’t access the Swagger UI:- Verify the API is running: Check the console for
Application is running on: http://localhost:3000 - Check the port: Ensure you’re using the correct port from
PORTenvironment variable - Check logs: Look for any startup errors related to Swagger setup
401 Unauthorized on Protected Endpoints
If you get 401 errors when testing protected endpoints:- Ensure you’ve called
/auth/loginand received a token - Click Authorize and enter
Bearer <token>(with the space) - Verify the token hasn’t expired (default: 1 hour)
- Check that the lock icon is closed (locked) on the endpoint
Rate Limit Errors in Swagger
If you encounter 429 errors while testing:- Login endpoint: Limited to 5 requests per 60 seconds
- Price endpoints: Limited to 20 requests per 60 seconds
- Wait for the rate limit window to reset or adjust
THROTTLE_*environment variables