A Spring Boot microservice that provides a REST API for fetching, storing, and converting currency exchange rates using live data from an external API. This project demonstrates a complete end-to-end workflow, from project setup to production-ready API.
- Fetch & Store Rates: Retrieve live exchange rates from the ExchangeRate API and persist them in an H2 database.
- Retrieve Latest Rate: Query the most recently stored rate for any currency pair.
- Convert Amounts: Convert monetary values using the latest stored rate.
- Error Handling: Returns meaningful HTTP status codes (
400,404,201,200). - Configuration-Driven: Externalize API keys and database settings in
application.yml. - Auto-Configuration & Starters: Leverage Spring Boot’s auto-configuration and starter dependencies for rapid development.
- Postman Collection: Includes a ready-to-import collection to test all endpoints and error scenarios.
currency-exchange-app/
├── src/main/java/com/drill/currencyexchangeapp/
│ ├── controller/ # REST controllers
│ ├── service/ # Service interfaces & implementations
│ ├── repository/ # Spring Data JPA repositories
│ ├── model/ # JPA entity classes
│ └── dto/ # External API response mappings
├── src/main/resources/
│ └── application.yml # Application configuration (DB, API keys, etc.)
├── src/test/java/ # Unit tests for service layer
├── pom.xml # Maven build file (dependencies & plugins)
└── README.md # Project documentation
- Java 8+
- Maven 3.6+
- (Optional) IDE: IntelliJ IDEA, Eclipse, VS Code
-
Clone the repository
git clone https://github.com/your-username/springboot-currency-exchange-service-backend.git cd springboot-currency-exchange-service-backend -
Obtain and configure your API key
-
Sign up for a free key at ExchangeRate API.
-
In your account dashboard, copy your API Key.
-
Open
src/main/resources/application.ymland replaceYOUR_API_KEY:exchange: api: url: https://v6.exchangerate-api.com/v6 # Base URL for all requests key: <YOUR_API_KEY> # ← Paste your key here
-
Verify you can fetch live rates:
curl https://v6.exchangerate-api.com/v6/$YOUR_API_KEY/latest/USD
-
exchange:
api:
url: https://v6.exchangerate-api.com/v6
key: YOUR_API_KEY # Replace with your key from ExchangeRate API-
Build & run the application
mvn clean install mvn spring-boot:run
-
Access H2 Console (for database exploration)
- URL:
http://localhost:8080/h2-console - JDBC URL:
jdbc:h2:mem:currencydb - User:
sa, Password: (leave blank)
- URL:
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/ping |
Health check, returns pong. |
| POST | /api/rates/fetch?from={from}&to={to} |
Fetches live rate, stores it, returns entity. |
| GET | /api/rates/latest?from={from}&to={to} |
Returns the most recently stored rate. |
| GET | /api/convert?from={from}&to={to}&amount= |
Converts the amount using the stored rate. |
Error Responses:
400 Bad Request: Invalid or unsupported currency codes.404 Not Found: No rate stored for the specified currency pair.
-
Unit Tests
mvn test -
Postman Collection
- Import
postman/ExchangeRateService.postman_collection.jsonto execute happy-path and error-case scenarios.
- Import
- Java 8+:
BigDecimal,Instant, Java 8 streams - Spring Boot: Auto-configuration, starter dependencies, embedded Tomcat
- Spring Data JPA: Entity mapping, CRUD, custom finder methods
- Hibernate: ORM, schema generation, transaction management
- WebClient: Reactive HTTP client for external API integrations
- H2 Database: In-memory persistence for rapid development
- REST API Design: Controllers, validation, HTTP status codes
- Error Handling: Custom exceptions,
@ControllerAdvice - Maven: Dependency & build management, plugins
- Testing: JUnit 5, Mockito, Spring Boot Test
- API Documentation: Postman collections for endpoint validation