Skip to main content

Endpoint

GET /api/rate
Retrieves the current USD to Bolivares (Bs) exchange rate used by the Mueve currency exchange system. This endpoint provides real-time rate information that is cached in Redis for optimal performance, with automatic fallback to the database if the cache is unavailable.

Authentication

No authentication required. This is a public endpoint.

Request

This endpoint does not require any parameters, headers, or request body.

Example Request

curl -X GET http://localhost:3001/api/rate
curl http://localhost:3001/api/rate

Response

The endpoint returns a JSON object containing the current USD to Bolivares exchange rate.

Response Fields

rate
number
required
The current USD to Bolivares exchange rate as a numeric value (e.g., 36.50 Bs per USD). This rate is retrieved from Redis cache for optimal performance. If Redis is unavailable, the system automatically falls back to the latest rate stored in the database.

Success Response

Status Code: 200 OK
{
  "rate": 36.50
}

Example Responses

Error Responses

message
string
Error message describing what went wrong during the request processing.
Status Code: 500 Internal Server Error
{
  "message": "Error interno del servidor"
}
This error occurs when there’s an unexpected server-side error during rate retrieval.

Implementation Details

The rate retrieval follows a resilient architecture:
  1. Redis Cache (Primary): The endpoint first attempts to retrieve the cached exchange rate from Redis using the key btc:value (note: despite the key name, this stores the USD to Bolivares rate). This provides the fastest response time for frequently accessed data.
  2. Database Fallback (Secondary): If Redis is unavailable, returns an invalid value, or the cached value cannot be parsed as a number, the system automatically queries the database for the latest stored rate.
  3. Graceful Degradation: If both data sources fail, the endpoint returns a user-friendly message indicating that data is temporarily unavailable, rather than throwing an error.
This multi-tier approach ensures high availability and optimal performance while maintaining data consistency.

Use Cases

  • Display current exchange rates to users in the application UI
  • Calculate transaction amounts for currency exchanges
  • Monitor rate fluctuations for analytics and reporting
  • Verify pricing before executing trades
  • Integration with third-party systems requiring current rate information

Notes

  • The rate value is cached in Redis for performance optimization
  • No rate limit is enforced on this endpoint as it’s read-only and lightweight
  • The rate is updated asynchronously by background processes
  • Response times are typically under 10ms when served from Redis cache
  • The endpoint does not support query parameters or request body data

Build docs developers (and LLMs) love