- Introduction
- What's in the project
- Running the application 3.1 Build - test - package from the source code 3.2 Run using docker or docker-compose 3.3 Run the Docker image from DockerHub
- About the code
This project is a microservice that serves the following API endpoints:
- Output the current time (GMT+1).
- Validate a VAT input and return corresponding country code.
- Convert currency input. Note: The free plan of the Currency Layer API only allows to get real-time rates from USD to desired currencies. Therefore, the
source
currency of the conversion feature is always USD.
- Source code that you can review.
- A micro-service that you can build, test & run yourselves.
- Documentation, where relevant.
- Incorporation of software engineering best-practices and design-patters where relevant.
- Test coverage to ensure code-quality.
- Service running on port 8081.
- BONUS: Autogenerated Swagger documentation.
- BONUS: Dockerfile with multi-layer build and relevant README instructions.
BONUS: Incorporate embedded DB/caching for API endpoints.
You can either run the application by building, testing and running the project from the source code, OR spin-up a container using docker and docker-compose, OR use the Docker image provided on DockerHub to run a container.
Prerequisites: Maven 3.6.1
, Java 11
- Download source code or clone it using
git clone https://github.com/rafikbelas/currensee.git
- Go to the project folder
cd currensee
- Run the following command
mvn clean
- Test the application by running
mvn test
- Run the application by running:
mvn spring-boot:run
. This will start the application on port 8081 http:https://localhost:8081/api/ - To test the API endpoints, head to the auto-generated Swagger documentation
Prerequisites: docker
ordocker-compose
- Download source code or clone it using
git clone https://github.com/rafikbelas/currensee.git
- Go to the project folder
cd currensee
- Option 1 (Using
docker-compose
): Run the following commanddocker-compose up
ordocker-compose up -d
. This will build a new image using the and spin-up a container. - Option 2 (Using
docker
): Run the following commandsdocker build -t currensee:latest . && docker run -dp 8081:8081 currensee
. This will build a new image if not existant and run a container from it. - To test the API endpoints, head to the auto-generated Swagger documentation
Prerequisites: docker
- Run the following command
docker run -dp 8081:8081 rafikbelas/currensee
. This will download thecurrensee
image from the DockerHub and run it. - To test the API endpoints, head to the auto-generated Swagger documentation
controller
: entry-point of each API. calls the appropriateservice(s)
with the received parameters and returns the corresponding response.service
: Services that hold the business logic, independently from external APIs, in case those are changed. Eventually calls other services in theservice > api
related to an external API.service > api
: Services that call external APIs, separated from business logic.dto
: Object responses returned by controller or received by external services.validator
: Custom validatorsconfiguration
: Custom configurationexception
: Custom exceptions and aGlobalExceptionHandler
to handle all exepctions thrown by thecontroller
.
The external APIs used are CurrencyLayer
and CloudMersive
.
The CloudMersive
API provides a ready SDK that was used in the service to call the API.
The GlobalExceptionHandler
provides exception handling to each error thrown by the controller and returns a custom response with
status
message
timestamp
debug message
(Optional)subErrors
(Optional): list of fields that cause the error.field
rejecteValue
message
Errors regarding the external APIs and API Keys are returned as INTERNAL_SERVER_ERROR
for now.