dijkstra-backend/README.md

139 lines
3.3 KiB
Markdown
Raw Normal View History

2020-02-08 19:50:22 +00:00
# dijkstra-backend
2020-02-10 02:34:19 +00:00
Find the the shortest path between different cities in Belgium with Dijkstra algorithm.
2020-02-08 19:50:22 +00:00
2020-03-20 13:16:40 +00:00
- Deployed Frontend: https://dijkstra.ruihildt.xyz/
- Deployed Backend: https://dijkstra-backend.herokuapp.com/
2020-02-08 19:50:22 +00:00
2020-09-28 16:18:37 +00:00
- Frontend Source: https://git.ruihildt.xyz/ruihildt/dijkstra-frontend
2020-02-08 19:50:22 +00:00
## API Documentation
___
> Values required in **`bold`**.
2020-02-09 17:06:33 +00:00
### COUNTRIES **`countries`**
2020-02-08 19:50:22 +00:00
| field | data type | metadata |
| :--------| :---------------- | :-------------------------------------------------- |
| id | unsigned integer | primary key, auto-increments, generated by database |
| name | string | |
#### Get countries list
2020-02-08 19:58:55 +00:00
**`GET /api/countries/:country_id`**
2020-02-08 19:50:22 +00:00
##### Response
2020-02-09 19:47:45 +00:00
An array of json objects with a list of cities in the selected country with `name`, `id` and `country_id`.
2020-02-08 19:50:22 +00:00
```
2020-02-08 19:58:55 +00:00
[
{
"id": 1,
"name": "bruges",
"country_id": 1
},
{
"id": 2,
"name": "antwerp",
"country_id": 1
},
{
"id": 3,
"name": "ghent",
"country_id": 1
},
]
2020-02-08 19:50:22 +00:00
```
2020-02-09 17:06:33 +00:00
### CITIES **`cities`**
2020-02-08 19:58:55 +00:00
| 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` |
2020-02-08 19:50:22 +00:00
#### Get cities list
**`GET /api/cities`**
##### Response
2020-02-09 19:47:45 +00:00
An array of json objects with `id`, `name` and `country_id`.
2020-02-08 19:50:22 +00:00
```
2020-02-09 19:47:45 +00:00
[
{
"id": 1,
"name": 'bruges',
"country_id": 1
}
]
2020-02-08 19:50:22 +00:00
```
2020-02-09 17:06:33 +00:00
### ROADS **`roads`**
2020-02-08 19:50:22 +00:00
| 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
2020-02-09 19:47:45 +00:00
A array of json objects with `id`, `start_city_id`, 'end_city_id` and `distance`.
2020-02-08 19:50:22 +00:00
```
2020-02-09 19:47:45 +00:00
[
{
"id": 1,
"start_city_id": 1,
"end_city_id": 3,
"distance": 50
}
]
2020-02-08 19:50:22 +00:00
```
2020-02-09 17:06:33 +00:00
### Shortest Path **`cities`**
2020-02-08 19:50:22 +00:00
#### Get the shortest path between two cities and the total distance
**`GET /api/path`**
##### Request
2020-02-09 17:06:33 +00:00
Add the **`start_city_id`** and **`end_city_id`** as query strings to the url.
2020-02-08 19:50:22 +00:00
```
2020-02-09 17:06:33 +00:00
/api/path?start_city_id=2?end_city_id=9
2020-02-08 19:50:22 +00:00
```
##### Response
2020-02-09 17:06:33 +00:00
A json object composed of the `path` correctly ordered and the total `distance`.
2020-02-08 19:50:22 +00:00
```
{
"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
}
2020-02-09 11:04:54 +00:00
```