API that receives a list of country codes as inputs and retrieve the countries that are in the same continents as the given countries. This API utilizes Trevorblades endpoint to acquire the information needed. Annexare project is used as data source for the countries as described in Trevorblades repository
The codes or names of the countries (case-insensitive). As an example, a possible input is BV (Bouvet Island) and TF (French Southern Territories)
{
"countries": ["BV", "TF"]
}
Alternatively, the input can be also the name of the countries or a mix of names and country codes (case-insensitive):
{
"countries": ["bouvet island", "French southern territories", "bV"]
}
The codes of the countries in the same continent of the input countries. As BV (Bouvet Island) and TF (French southern territories) are in Antarctica the result will be all the countries in this continent except for the input countries.
{
"message": "There are 3 countries in the same continents as the input countries bouvet island,French southern territories,bV",
"countriesInput": [
"bouvet island",
"French southern territories",
"bV"
],
"countriesOutput": [
{
"code": "AQ",
"name": "Antarctica",
"continent": {
"code": "AN",
"name": "Antarctica"
}
},
{
"code": "GS",
"name": "South Georgia and the South Sandwich Islands",
"continent": {
"code": "AN",
"name": "Antarctica"
}
},
{
"code": "HM",
"name": "Heard Island and McDonald Islands",
"continent": {
"code": "AN",
"name": "Antarctica"
}
}
]
}
Instead of hitting the Trevorblades API every time that this Takehome API is called, the idea of this project is doing a pre-processing phase loading the data needed. Using this approach, this API does not need to call any other endpoint per request and the response can be acquired quicker, the resources used are lower (cpu and memory), and this API can handle a request rate much higher.
The pre-processing part does not guarantee that the response is always up-to-date with the most recent continent and country divisions. For reducing the possibility of outdated data, this API could reduce the refresh time of the pre-processing step or adding a manual refreshing feature. The refresh was configured to be performed each 15 days.
This API allows both authenticated and unauthenticated users to access, but it limits the number of requests per minute differently for them.
As unauthenticated users can access the API, it does not block any user trying to access it.
Also, if the continents code comes to change, this API would need a modification in the enum related to them.
./gradlew bootRun
./gradlew build
java -jar build/libs/takehome-{version}.jar
./gradlew test
docker-compose up --build
For scaling up the API for 3 servers (for example) simply use docker-compose with the docker-compose-scale.yml:
docker-compose --file docker-compose-scale.yml up -d --build --scale takehome-server=3
docker build -t takehome .
docker run -d -p 8080:8080 takehome