Implementation of REST adaptor to an external data source (Hexagonal Architecture with Spring Boot — Part 5)
This is the fourth article of a 4 5 part series explaining Hexagonal Architecture and how to implement such an architecture using Spring Boot and TDD.
Part 1 - Introduction to Hexagonal Architecture and Key Concepts
Part 2 - Coding demo project and implementation of the API adaptor
Part 3 - Implementation of Domain Services
Part 4 - Implementation of MongoDB repository adaptor
Part 5 - Implementation of REST adaptor to an external data source
Part 2 of the video is live now:
REST Adapter for Stock Market Price
To complete the service, the last interface to implement is GetStockMarketPricePort
for retrieving the market price of the stock. We will use the free service form AlphaVantage for this.
There are several providers with different service levels and pricing that you could close from, and you can choose any and implement the corresponding adapter, without changing any other parts of the source code. Herein lies the power of the hexagonal architecture to modularise the code.
We start by choosing a suitable API endpoint to provide the required data, in this case since we only need the last closing price, we can use the TIME_SERIES_DAILY
endpoint.
We’ll need a JSON mapper for the data returned by this endpoint, so let’s download a sample and place it into the test resource test/respurces/alphavantage-samples/time-series-daily.json
.