A lightweight REST API for retrieving foreign exchange rates, built with Go and backed by Google Cloud Firestore.
- π Fast and lightweight HTTP server using Go's standard library
- πΎ Firestore database for storing exchange rate data
- π Support for multiple base currencies
- π― Filter rates by specific currency symbols
- π³ Docker support for easy deployment
- π Request logging middleware
- Go 1.24+ (or Docker)
- Google Cloud Platform account with Firestore enabled
- just command runner (optional, for development)
- reflex for hot-reloading during development
- Node.js 18+ and npm (for running integration tests via Firebase emulator)
| Variable | Description | Required |
|---|---|---|
GCP_PROJECT_ID |
Google Cloud Project ID with Firestore | Yes |
SERVER_ADDRESS |
Full server address (e.g., 127.0.0.1:8000) |
No |
PORT |
Port number (used if SERVER_ADDRESS not set) |
Conditional |
FIRESTORE_EMULATOR_HOST |
Firestore emulator address for local development | No |
git clone https://github.com/kamaal111/forex-api.git
cd forex-apigo mod download-
Start the Firestore emulator:
just start-db
-
In a new terminal, start the development server with hot-reloading:
just dev
export GCP_PROJECT_ID=your-project-id
export SERVER_ADDRESS=127.0.0.1:8000
go run .just build
# or
docker build -t forex-api .just run
# or
docker run -dp 8000:8000 --name forex-api \
-e GCP_PROJECT_ID=your-project-id \
-e PORT=8000 \
forex-apiGET /v1/rates/latest
Retrieves the most recent exchange rates for a given base currency.
| Parameter | Description | Default |
|---|---|---|
base |
Base currency code (e.g., USD, EUR) |
EUR |
symbols |
Comma-separated list of currency codes to filter (e.g., USD,GBP,JPY) |
All currencies |
curl "http://localhost:8000/v1/rates/latest?base=USD&symbols=EUR,GBP,JPY"{
"base": "USD",
"date": "2025-11-30",
"rates": {
"EUR": 0.92,
"GBP": 0.79,
"JPY": 149.50
}
}The API supports the following currencies:
- Major: EUR, USD, GBP, JPY, CHF, CAD, AUD, NZD
- European: BGN, CZK, DKK, HUF, PLN, RON, SEK, NOK, ISK, HRK
- Asian: CNY, HKD, IDR, INR, KRW, MYR, PHP, SGD, THB
- Americas: BRL, MXN
- Other: ILS, TRY, ZAR
- Historical: CYP, EEK, LTL, LVL, MTL, ROL, SIT, SKK, TRL
forex-api/
βββ main.go # Application entry point
βββ go.mod # Go module dependencies
βββ Dockerfile # Docker container configuration
βββ justfile # Development task runner commands
βββ database/
β βββ database.go # Firestore client initialization
βββ handlers/
β βββ rates.go # HTTP request handlers for rates endpoint
βββ routers/
β βββ routers.go # Main router setup and server start
β βββ rates.go # Rates route group
β βββ middleware.go # Request logging middleware
β βββ errors.go # Error handling routes
βββ utils/
βββ environment.go # Environment variable helpers
βββ errors.go # Error response utilities
βββ strings.go # String utility functions
All errors are returned in JSON format:
{
"message": "Error description",
"status": 404
}The development setup uses reflex for automatic recompilation when Go files change:
go install github.com/cespare/reflex@latest
just devFor local development without connecting to Google Cloud:
# Install Google Cloud SDK if not already installed
# https://cloud.google.com/sdk/docs/install
just start-dbThis starts the Firestore emulator on 127.0.0.1:8080.
- Unit tests:
just testornpm run test:unit
- Integration tests (Firestore emulator managed automatically):
just test-integrationornpm test
- All tests (unit + integration):
just test-allornpm run test:all
- Coverage:
just test-coverorjust test-cover-html
Requirements for integration tests:
- Node.js 18+;
firebase-toolsis installed as a dev dependency and started by the npm scripts. - No external GCP access is required; the tests seed data into the emulator.
See AGENTS.md for contributor guidelines, coding style, and PR expectations.