Overview
This guide walks you through setting up the Currency Converter API from scratch. You’ll configure environment variables, set up Docker containers, and obtain API keys from currency exchange providers.Prerequisites
Before you begin, ensure you have:- Docker and Docker Compose installed
- Git for cloning the repository
- API keys from at least one currency provider (recommended: all three for redundancy)
Environment configuration
Copy environment template
The repository includes an example environment file with all required variables:This creates your local
.env file that you’ll customize with your specific configuration.Configure environment variables
Open the
.env file and configure the following sections:Application settings
Server configuration
Database configuration
When running with Docker Compose, replace
localhost with the service name db in the DATABASE_URL.Redis configuration
API provider settings
Configure your API keys for the currency exchange providers:Obtaining API keys
The Currency Converter API uses multiple providers for redundancy and accuracy. You need to obtain API keys from each provider.Fixer.io API key
Fixer.io API key
- Visit https://fixer.io/
- Click “Get Free API Key” or “Sign Up”
- Complete the registration form
- Verify your email address
- Copy your API key from the dashboard
- Add it to your
.envfile asFIXERIO_API_KEY
- 100 requests per month
- Real-time exchange rates
- 170+ currencies
OpenExchangeRates App ID
OpenExchangeRates App ID
- Visit https://openexchangerates.org/
- Click “Sign Up” in the top right
- Choose the “Free” plan
- Complete the registration
- Your App ID will be displayed on the dashboard
- Add it to your
.envfile asOPENEXCHANGE_APP_ID
- 1,000 requests per month
- Hourly updates
- 200+ currencies
CurrencyAPI key
CurrencyAPI key
- Visit https://currencyapi.com/
- Click “Get Free API Key”
- Sign up with your email
- Verify your account
- Copy the API key from your dashboard
- Add it to your
.envfile asCURRENCYAPI_KEY
- 300 requests per month
- Real-time rates
- 150+ currencies
While you can run the API with just one provider, using all three ensures maximum reliability and accuracy through rate averaging.
Docker setup
The Currency Converter API uses Docker Compose to orchestrate multiple services.Start services
Launch all services with a single command:This command:
- Starts PostgreSQL on port 5432
- Starts Redis on port 6379
- Creates persistent volumes for data
- Runs containers in detached mode
Verify services are running
Check that all containers are healthy:You should see both
db and redis services with status “Up”.Starting the API
Once your environment is configured and services are running, start the API server.Using Docker
Using Poetry (local development)
If you prefer running locally without Docker:Verifying installation
Check API health
Visit the API documentation to confirm it’s running:You should see the Swagger UI interface in your browser at
http://localhost:8000/docs.Test supported currencies endpoint
Verify that the API successfully initialized supported currencies:Expected response:
On first startup, the API fetches supported currencies from all providers and stores them in the database. This may take a few seconds.
Troubleshooting
Database connection errors
Database connection errors
If you see
Connection refused errors:-
Verify PostgreSQL is running:
-
Check the DATABASE_URL in your
.envfile -
Ensure the hostname matches your Docker service name (usually
dbwhen using Docker Compose) -
Verify credentials match between
.envanddocker-compose.yml
Redis connection errors
Redis connection errors
If Redis connections fail:
-
Check Redis is running:
-
Verify REDIS_URL in your
.envfile -
Test Redis connection:
PONGProvider API errors
Provider API errors
If you see “Provider unavailable” errors:
-
Verify your API keys are correct in the
.envfile - Check you haven’t exceeded your free tier limits
-
Test provider connectivity manually:
- Ensure at least one provider is working (the API can function with a single provider)
Port conflicts
Port conflicts
If ports 8000, 5432, or 6379 are already in use:
-
Modify the port mappings in
docker-compose.yml: -
Update your
.envfile to match the new ports - Restart the services
Next steps
Now that your Currency Converter API is set up and running:- Learn how to use the API endpoints
- Understand error handling strategies
- Optimize performance with caching
