Sign inSign up

optiwariindia/exrate

By optiwariindia

•Updated 3 months ago

Exchange rate API with daily caching and currency conversion support.

Image
API management
0

228

optiwariindia/exrate repository overview

⁠Overview

The optiwariindia/exrate image contains a lightweight, production-ready application that serves currency exchange rate data. It exposes a simple REST API to fetch current rates and perform currency conversions.

The application is designed to be efficient by caching the exchange rate data daily. On its first run of the day, it will fetch data from an external API and save it to a local file. Subsequent requests on the same day will use the cached data, reducing latency and external API calls.


⁠Configuration

You can configure the container using environment variables, port mappings, and volume mounts.

Ports

The application inside the container listens on port 8080. You must map a port from your host machine to the container's port 8080 to access the API.

  • Container Port: 8080

Volumes

The application uses a directory to cache the daily exchange rate data. To ensure this data persists across container restarts, you should mount a volume to the cache directory inside the container.

  • Container Cache Path: /app/exrate

Environment Variables

  • EXRATE_API_URL: (Required) This variable specifies the URL of the external exchange rate API to fetch data from. The application is compatible with APIs that return data in a similar format to openexchangerates.org or frankfurter.dev.
    • Example for Frankfurter.dev: https://api.frankfurter.dev/v1/latest?base=USD
    • Example for Open Exchange Rates: https://openexchangerates.org/api/latest.json?app_id=YOUR_APP_ID

⁠How to Use with Docker Compose

Using docker-compose is the recommended way to run this image, as it simplifies the management of ports, volumes, and environment variables. Your existing docker-compose.yml already has a perfect example in the exrate-prod service.

Here is a breakdown of that service definition for clarity:

docker-compose.yml service definition:

services:
  exrate:
    # Specifies the image to pull from Docker Hub.
    image: optiwariindia/exrate:1.0.0

    # Maps port 80 on the host to port 8080 in the container.
    # You can access the API at http://localhost
    ports:
      - 80:8080

    # Mounts the local './exrate' directory into the container at '/app/exrate'.
    # This is crucial for persisting the daily cache on your host machine.
    volumes:
      - ./exrate:/app/exrate

    # Sets the external API URL for fetching exchange rates.
    environment:
      - EXRATE_API_URL=${EXRATE_API_URL}
⁠Running the Service
  1. Make sure you have a docker-compose.yml file with the content above.
  2. Create the local cache directory:
    mkdir -p exrate
    
  3. Run the service using the following command:
    # This command will start the service in the foreground.
    docker-compose up exrate-prod
    
    To run it in the background (detached mode), use:
    docker-compose up -d exrate-prod
    

You can now access the API at http://localhost/api/v1/exchangerate.

Tag summary

Content type

Image

Digest

sha256:3dc17565a…

Size

2.7 MB

Last updated

3 months ago

docker pull optiwariindia/exrate:go-1.0.0