Skip to main content

Introduction

The CryptoPulse API is a NestJS-based service that provides cryptocurrency price data with intelligent request batching, persistence, and JWT authentication. The API is designed to handle multiple concurrent instances with Redis-backed coordination.

Base URL

The default base URL for the API is:
http://localhost:3000
In production environments, this will be your deployed domain.

API Version

Current API version: v1.0.0 Price endpoints are versioned with the /v1 prefix:
  • /v1/price/:coinId
  • /v1/price/:coinId/history

Available Endpoints

Authentication

MethodEndpointDescriptionAuth Required
POST/auth/loginAuthenticate and receive JWT tokenNo

Price Data

MethodEndpointDescriptionAuth Required
GET/v1/price/:coinIdGet current USD price for a coin (batched)Yes
GET/v1/price/:coinId/historyGet paginated historical pricesYes

Key Features

Request Batching

The API automatically batches requests for the same coin to optimize upstream API calls:
  • Batch Window: 5 seconds (configurable)
  • Early Flush Threshold: 3 pending requests (configurable)
  • Multiple requests for the same coin are served from a single upstream call

Rate Limiting

Built-in throttling protects the API from abuse:
  • Global Limit: 20 requests per 60 seconds
  • Login Limit: 5 requests per 60 seconds
  • Redis-backed counters work across multiple instances

Data Persistence

All successful price fetches are automatically saved to PostgreSQL, enabling:
  • Historical price tracking
  • Date range queries
  • Paginated results

Interactive Documentation

Swagger/OpenAPI documentation is available at:
http://localhost:3000/docs
The interactive documentation includes:
  • Complete endpoint specifications
  • Request/response examples
  • Error code documentation
  • Built-in “Try it out” functionality
  • Bearer token authorization UI

Using Swagger Docs

  1. Navigate to http://localhost:3000/docs
  2. Use POST /auth/login to get an access token
  3. Click the Authorize button at the top
  4. Enter: Bearer <your-access-token>
  5. Test protected endpoints directly in the browser

Response Format

All API responses follow a consistent JSON format:

Success Response

{
  "coinId": "bitcoin",
  "vsCurrency": "usd",
  "price": 67210.45,
  "fetchedAt": "2026-02-28T03:55:00.000Z"
}

Error Response

{
  "statusCode": 401,
  "message": "Invalid credentials",
  "error": "Unauthorized"
}

Common Status Codes

CodeStatusMeaning
200OKRequest successful
400Bad RequestInvalid request parameters
401UnauthorizedMissing or invalid authentication
404Not FoundCoin not found
429Too Many RequestsRate limit exceeded
502Bad GatewayUpstream service error
503Service UnavailableBackend unavailable (Redis/database)
504Gateway TimeoutRequest timeout

Next Steps

Authentication

Learn how to authenticate and use JWT tokens

Get Price

Fetch current cryptocurrency prices

Price History

Query historical price data

Error Handling

Handle API errors gracefully

Build docs developers (and LLMs) love