Skip to content

A SpringBoot application exposing an end-point to check if two cities are connected. It internally uses the BFS algorithm to traverse the graph.

Notifications You must be signed in to change notification settings

rameshdhas/city-networks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Contents


About City Connections

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.

Features

  • 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.

Live Demo

Checkout the live demo of City Connections.

Checkout the Swagger documentation at API Documentation.

THe application is hosted in Heroku environment.

Getting started

To run (with Maven)

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

To run test cases (with Maven)

git clone https://github.com/rameshdhas/city-networks.git

cd city-networks

mvn test

Executing API calls

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.

For Example:

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


FAQ

Where can I learn more about spring boot?

The Spring Boot page contains several useful guides.

Is the data stored in memory?

Yes! All the data from cities.txt is loaded into the server's memory. It's just stored in a plain java HashMap.

Can I load my own data?

You can!

Create the data file cities.txt, one pair per line, comma separated and copy to resources folder.

Restart the application.

Can I build my own algorithms?

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.

Where do I report issues with the city-connections API?

If something is not working as expected, please open an issue.

Swagger

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.

License

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.

Apache-2.0

Thank you!

About

A SpringBoot application exposing an end-point to check if two cities are connected. It internally uses the BFS algorithm to traverse the graph.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published