Skip to content

API to retrieve information about countries' geography.

Notifications You must be signed in to change notification settings

andregsimao/takehome

Repository files navigation

takehome

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


Endpoint to find countries in the same continent that the given countries

Example: Input countries -> BV (Bouvet Island) and TF (French Southern Territories)

POST request to localhost:8080/takehome/countries/same-continent

Input

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"] 
}

Output

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"
      }
    }
  ]
}

Implementation

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.

Limitations

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.

Suppositions

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.

Build & Run

run spring-boot application

./gradlew bootRun

build and execute jar with JDK 17

./gradlew build
java -jar build/libs/takehome-{version}.jar

run tests

./gradlew test

For building OCI image and running it as a container, simply use docker-compose:

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 

Alternatively, to build OCI image and run the image inside as a container

docker build -t takehome .
docker run -d -p 8080:8080 takehome

About

API to retrieve information about countries' geography.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published