Skip to content

Latest commit

 

History

History
160 lines (121 loc) · 3.67 KB

File metadata and controls

160 lines (121 loc) · 3.67 KB

Exchange Rate Updater API

A .NET API for retrieving currency exchange rates from the Czech National Bank (CNB). The program for testing the currencies defined in the original repository runs on the startup of Program.cs in the development environment.

Features

  • Retrieve exchange rates for specific currency pairs
  • Support for batch requests of multiple currency pairs
  • Date-specific exchange rate data
  • Redis caching for improved performance
  • Health checks for monitoring API and dependencies
  • Containerization with Docker and docker-compose

Architecture

The solution follows clean architecture principles:

  • Core Layer: Domain models, interfaces, and business logic
  • Infrastructure Layer: External integrations (CNB, Redis cache)
  • API Layer: HTTP endpoints, controllers, and configuration

Running the API

Prerequisites

  • .NET 9.0 SDK
  • Docker & Docker Compose

Using Docker Compose

# Start the API and Redis
docker-compose up --build

The API will be available at:

Development Setup

# Restore packages
dotnet restore

# Run the API
cd src/ExchangeRateUpdater.Api
dotnet run

API Documentation

The API includes Swagger documentation available at the root URL when running in development mode.

Endpoints

Get Exchange Rate

GET /api/v1/ExchangeRate?sourceCurrency={sourceCurrency}&targetCurrency={targetCurrency}&date={date}
  • sourceCurrency: Source currency code (e.g., USD)
  • targetCurrency: Target currency code (e.g., CZK)
  • date (optional): Date in ISO-8601 format (yyyy-MM-dd)

Example:

GET /api/v1/ExchangeRate?sourceCurrency=USD&targetCurrency=CZK&date=2025-05-16

Response:

{
  "sourceCurrency": "USD",
  "targetCurrency": "CZK",
  "rate": 22.274,
  "date": "2025-05-16",
  "datePublished": "2025-05-16"
}

Batch Exchange Rates

POST /api/v1/ExchangeRate/batch

Request Body:

{
  "date": "2025-05-16",
  "currencyPairs": [
    "USD/CZK",
    "EUR/CZK",
    "GBP/CZK"
  ]
}

Response:

{
  "date": "2025-05-16",
  "datePublished": "2025-05-16",
  "rates": [
    {
      "sourceCurrency": "USD",
      "targetCurrency": "CZK",
      "rate": 22.274,
      "date": "2025-05-16",
      "datePublished": "2025-05-16"
    },
    {
      "sourceCurrency": "EUR",
      "targetCurrency": "CZK",
      "rate": 24.930,
      "date": "2025-05-16",
      "datePublished": "2025-05-16"
    },
    {
      "sourceCurrency": "GBP",
      "targetCurrency": "CZK",
      "rate": 29.587,
      "date": "2025-05-16",
      "datePublished": "2025-05-16"
    }
  ]
}

Health Checks

The API includes health check endpoints:

  • /health/live: Basic application health
  • /health/ready: Checks dependencies (Redis, CNB API)

Notes on CNB Data

Production Readiness

To be production ready the following needs to be added:

  • Use Azure Key Vault or similar for managing secrets in production
  • Enable HTTPS with valid SSL certificates
  • Configure proper network security groups and firewall rules
  • Set up monitoring and alerting (Grafana, SlACK)
  • Implement rate limiting for API endpoints
  • Add a deployment pipeline (GitHub Actions, Azure DevOps)
  • Deploy to a cloud service (Azure App Service, AWS Lambda, Kubernetes)