An application using SpringBoot & Java (1.8 or above) which determines if two cities are connected. Two cities are considered connected if there’s a series of roads that can be traveled from one city to another.
List of roads is available in a file. The file contains a list of city pairs (one pair per line, comma separated), which indicates that there’s a road between those cities.
- Rest API - REST end-point available to check two cities are connected.
- Speedy Implementation - Install and run the application in five minutes.
- Data Load - Loads the data file cities.txt from resources folder during server start.
- Customizable - Build your data file (cities.txt) and check the city connections.
- Flexible back-end - New features can be added in the MapService and exposed as REST end-points.
Checkout the live demo of City Connections.
Checkout the Swagger documentation at API Documentation.
THe application is hosted in Heroku environment.
To run the server, run this task:
git clone https://github.com/rameshdhas/city-networks.git
cd city-networks
mvn clean install
cd target
java -jar city-networks-0.0.1-SNAPSHOT.jar
Tha application will start in the http port 8080
git clone https://github.com/rameshdhas/city-networks.git
cd city-networks
mvn test
Tha application is deployed as a Spring Boot App and it exposes one endpoint: http://localhost:8080/connected?origin=city1&destination=city2
The end pont will respond with ‘yes’ if city1 is connected to city2, ’no’ if city1 is not connected to city2. Any unexpected input should result in a ’no’ response.
cities.txt content is:
Boston, New York
Philadelphia, Newark
Newark, Boston
Trenton, Albany
https://city-connections.herokuapp.com/connected?origin=Boston&destination=Newark Should return yes
https://city-connections.herokuapp.com/connected?origin=Boston&destination=Philadelphia Should return yes
https://city-connections.herokuapp.com/connected?origin=Philadelphia&destination=Albany Should return no
The Spring Boot page contains several useful guides.
Yes! All the data from cities.txt is loaded into the server's memory. It's just stored in a plain java HashMap.
You can!
Create the data file cities.txt, one pair per line, comma separated and copy to resources folder.
Restart the application.
Yes! Absolutely.
The current API uses breath first search (BFS) algorithm to check if the cities are connected. Another feature request would be to implement Dijkstra's shortest path between two cities.
If something is not working as expected, please open an issue.
Swagger UI allows anyone — be it your development team or your end consumers — to visualize and interact with the API’s resources without having any of the implementation logic in place. It’s automatically generated from your OpenAPI (formerly known as Swagger) Specification, with the visual documentation making it easy for back end implementation and client side consumption
Checkout the Swagger documentation at API Documentation.
The 2.0 version of the Apache License, approved by the ASF in 2004, helps us achieve our goal of providing reliable and long-lived software products through collaborative open source software development. All packages produced by the ASF are implicitly licensed under the Apache License, Version 2.0, unless otherwise explicitly stated.
Thank you!