An app using Dijkstra algorithm to find the shortest path between different cities. https://dijkstra-backend.ruihildt.xyz
Go to file
2020-02-10 03:34:19 +01:00
api Update doc 2020-02-09 18:06:33 +01:00
data Remove unused files 2020-02-08 21:09:36 +01:00
helpers Remove unused files 2020-02-08 21:09:36 +01:00
.gitignore first commit 2020-02-07 17:55:43 +01:00
index.js Add Readme 2020-02-08 20:50:22 +01:00
knexfile.js first commit 2020-02-07 17:55:43 +01:00
package-lock.json Add package to allow CORS and helmet for security 2020-02-09 11:59:23 +01:00
package.json Add package to allow CORS and helmet for security 2020-02-09 11:59:23 +01:00
README.md Update deployment links 2020-02-10 03:34:19 +01:00

dijkstra-backend

Find the the shortest path between different cities in Belgium with Dijkstra algorithm.

API Documentation


Values required in bold.

COUNTRIES countries

field data type metadata
id unsigned integer primary key, auto-increments, generated by database
name string

Get countries list

GET /api/countries/:country_id

Response

An array of json objects with a list of cities in the selected country with name, id and country_id.

[
  {
    "id": 1,
    "name": "bruges",
    "country_id": 1
  },
  {
    "id": 2,
    "name": "antwerp",
    "country_id": 1
  },
  {
    "id": 3,
    "name": "ghent",
    "country_id": 1
  },
]

CITIES cities

field data type metadata
id unsigned integer primary key, auto-increments, generated by database
name string
country_id unsigned integer foreign key referencing countries.id

Get cities list

GET /api/cities

Response

An array of json objects with id, name and country_id.

[
  {
    "id": 1,
    "name": 'bruges',
    "country_id": 1
  }
]

ROADS roads

field data type metadata
id unsigned integer primary key, auto-increments, generated by database
start_city_id string required
end_city_id string required
distance unsigned integer

Get roads list

GET /api/roads

Response

A array of json objects with id, start_city_id, 'end_city_idanddistance`.

[
  {
    "id": 1,
    "start_city_id": 1,
    "end_city_id": 3,
    "distance": 50
  }
]

Shortest Path cities

Get the shortest path between two cities and the total distance

GET /api/path

Request

Add the start_city_id and end_city_id as query strings to the url.

/api/path?start_city_id=2?end_city_id=9
Response

A json object composed of the path correctly ordered and the total distance.

{
  "path": [
    {
      "id": 2,
      "name": "antwerp"
    },
    {
      "id": 4,
      "name": "mechelen"
    },
    {
      "id": 5,
      "name": "brussels"
    },
    {
      "id": 8,
      "name": "liege"
    },
    {
      "id": 7,
      "name": "namur"
    },
    {
      "id": 9,
      "name": "arlon"
    }
  ],
  "distance": 337
}