Let's walk through this task:
- Create a new Java / Kotlin Micro-Service Application, utilizing Spring Boot.
- Serve the following API endpoints: Output the current time (as valid JSON) Convert currency inputs endpoint: /api/currency/convert inputs: amount (in source-currency), source-currency, target-currency output: amount in target-currency (as valid JSON) you may use static conversion data or connect to a public converter (e.g. https://currencylayer.com/documentation) Validate a VAT input and return input: potential VAT number output: country (code) for VAT number (as valid JSON) you may use a static mapping or connect to a public api (e.g. https://api.cloudmersive.com/swagger/index.html? urls.primaryName=Validate%20API)
- Add unit-test coverage as appropriate.
- Ensure the service can be built, tested, and run. The service should run on port 8081
BONUS: incorporate an embedded DB/caching layer for your API endpoints BONUS: The service includes autogenerated swagger documentation.
- Add a README to: describe the application, the pre-requisites, how to run it, additional notes, etc.
- Package the app and share a download link to the source-code or private GitHub repository.
WARNING: DO NOT INCLUDE THE BUILD/OUTPUT. We expect to be able to build, test, and run it ourselves. Please do not make the source-code public. BONUS: dockerize your application (i.e. include a Dockerfile, docker-compose.yml, and relevant README instructions)
For implementation as Micro-service architecture, Spring cloud technology is used, Netflix Eureka server is used for service registry. For the sake of this task, a single micro-service as the eureka client is created along with a eureka server. The complete application is created using the test-driven approach. That's is the reason application contains a large number of test cases. In netflix-client, two controllers are written, which details on abstraction level is given hereinafter. API is configured on port 8081
- CurrencyConverterController
- VATController
CurrencyConverterController is a rest controller which further consists of two types of API, keep in mind that each rest API is created while keeping in mind of the 2nd-degree maturity level of Rest API level defined by Richardson, In future commits, API will be upgraded to 3rd degree using HATEOAS.
1- API documentations and details are created using swagger 3.0, common objects are using created by swagger 3.0. Swagger configuration file is placed under resources with the namme of api.yaml
2- Logging also implementated with rolling file policy. its configuration is also available under resource folder.
3- Keep in mind that you are not able to run application until you did not start the eureka server, as the client needs to register itself with the server (configuration provided in the application).
4- For currency conversion and vat validation two different free API used, Those API are connected using Netflix-Feign declarative HTTP client which is also the part of Spring cloud technology.
5- For cache H2-Database used as in memory database. To avoid any dirty reads/write, phantom reads, repeated reads, Java ReadWriteReenterentLock is used.
6- Controller advice is written to handle exception and send respective response.
7- Spring AOP is used to logging each method enterence and exit.
8- Spring scheduler is writter to schedule cache refresher with a specific time interval.
9- Spring boot dockerization is added using spotify maven plugin for docker, by running command mvn package docker:build. After creating image you can see image in your docker by docker image ls. Now lets add tag to that image by command docker tag image_id TAG_NAME. After that you can push image to your docker hub by docker push TAG_NAME
Application is completely dockerize and images are uploaded to docker-hub with the name aqibbutt3078/ccvatapi for micro-service eureka client and aqibbutt3078/ccvatapi_eureka for eurka server
Currency Converter API consists on two API's
- /api/currency/convert?source=SOURCE_COUNTRY_CODE&target=TARGET_COUNTRY_CODE&amount=AMOUNT_NUMBER
- /api/currency/convert/details?source=SOURCE_COUNTRY_CODE&target=TARGET_COUNTRY_CODE&amount=AMOUNT_NUMBER
First API will going to return convertion detailes as it was asked in task, second API return details with some additional inVAT_ID
VATController also provides two API's
- /api/vat/validate?vat=VAT_ID
- /api/vat/validate/details?vat=VAT_ID
For each class, methods unit tests are provided. As application is build using red-green-refactor sort of test driven approach, so thats a reason it have alot of test cases. Integration test for Rest API is provided sepreatly.
Please click the url to see all currencies list https://free.currconv.com/api/v7/countries?apiKey=4754c8fa8c0d8e08c658