The application finds a land route between two countries based on list of countries located at : https://raw.githubusercontent.com/mledoze/countries/master/countries.json
.
To calculate the route, list of each country borders (neighbourgh countries) from the above URL is used.
Upon start, the application exposes a single service, /routing/{origin}/{destination}
, that allows to search for a route by country codes (cca3).
Results are returned as an array of codes of countries between (and including) origin and destination.
If land route between the countries does not exist, or if one of the country codes is not found, the application responds with HTTP status code 400 and a simple JSON object with details of the error.
Using git and maven:
git clone https://github.com/xalbrech/Routing.git
.cd Routing
mvn package
- The WAR is located in subdirectory
target/
.
On a checked-out project, run maven:
git clone https://github.com/xalbrech/Routing.git
mvn spring-boot:run
- Spring Boot starts a web container at local port 8080
- To test the application, open a new browser window and navigate to:
http://localhost:8080/routing/CZE/ITA
- The service shall return:
{"route":["CZE","AUT","ITA"]}
Important units of the source:
xalbrech.exercises.routing.map.CountryMap
Loads and maintains the map dataxalbrech.exercises.routing.calculation.RouteCalculator
Performs actual calculation of the route (uses a bfs to traverse the data provided byCountryMap
)xalbrech.exercises.routing.controller.RoutingController
REST controller that defines the/routing
endpoint.