Example microservice written in Scala using some modern FP libraries.
Disclaimer: This project serves as piece of my code. In production code there would be quite a few changes.
- Use case
- How to run application locally
- Endpoints
- Example request
- Configuration
- Tests
- Assumptions
- Why I used http4s (library) over for example Play (framework)?
- Possible improvements
The use case in this system is quite simple. We want to use configurable forex system proxy to be independent of the underlying system that keep the actual values. We might use one system today and decide that we want to change it tomorrow. We don't
As this project is a sbt
application you can either import it to your IDE fo choice e.g. IntelliJ or execute sbt run
from the rot folder.
By default, the app serves traffic at localhost:8092
.
Rest endpoints listed below:
Method | Url | Parameters | Description |
---|---|---|---|
GET | /rates | firstCurrency, secondCurrency | Returns latest currency rates from external source - API |
Some example request that might be executed via curl or in browser http://localhost:8092/rates?firstCurrency=USD&secondCurrency=JPY
The application might be configured by changing application.conf
in resources.
Things that might be changed are
- forex system that we use (currency rates provider)
- token (its name and value)
- application config (hostname and port used by the app)
To run tests execute sbt test
. You will run all unit tests.
To run integration tests start a Docker image by doing docker-compose up
in root. After that run sbt it:test
or run CurrencyServerSpec.scala
from IDE.
Project has a few assumptions. The proxy does not validate whether the passed currencies are valid or not. User might pass not supported currency but the assumption is that the underlying Forex API will respond with appropriate message.
It is much better to have full control over what's happening in my application than rely on some runtime magic and annotations. That's why I've chosen http4s library over Play. Might have used tapir, typedApi or akka-http as well.
- Add Swagger integration for API documenting
- Add continuous integration
- Add property based testing