This is a simple Spring Boot project that is able to calculate any possible land route from one country to another using JSON parsed data from mledoze/countries loaded at start-time. For every valid request Breadth First Search is used to find the shortest path (the lowest number of other countries) needed to cross when travelling from source to the destination country.
For building and running the application you need:
There are several ways to run a Spring Boot application on your local machine. One way is to execute the main
method
in the com/adrianr/landroutes/LandRoutesApplication.java
class from your IDE.
Alternatively you can use the Spring Boot Maven plugin like so:
mvn spring-boot:run
The easiest way to build this application is to use the Spring Boot Maven plugin like so:
mvn clean install
This will create:
- An JAR called "land-routes-0.0.1-SNAPSHOT"
If you want to access run the artefact resulted from the build process, you can use the following command:
java -jar land-routes-0.0.1-SNAPSHOT.jar
The application starts up and uses port 8080, in order to use it to check the distance between two different countries it exposes an endpoint at:
http://localhost:8080/routing/{source}/{destination}
Replace the following parameters with country codes in ISO 3166-1 alpha-3 format.
source
destination
Example:
http://localhost:8080/routing/CZE/ITA
Will respond with
Status Code | Description | Message |
---|---|---|
200 | OK |
{
"route": [ "CZE", "AUT", "ITA" ]
} |
If any of the country codes are invalid or there is no land path between the two countries then the response status for the request will:.
Status Code | Description | Message |
---|---|---|
404 | NOT FOUND |
{
"timestamp": "2021-11-06T10:11:32.114+00:00",
"status": 404,
"error": "Not Found",
"path": "/routing/ROU/CZEC"
} |