Python version of http://github.com/mdsrosa/routes_api
API to calculate the shortest path and the cost to a given route (origin point and destination point), based on fuel price and vehicle's autonomy.
This application is live on Heroku: https://routes-api-python-prod.herokuapp.com
$ git clone https://github.com/mdsrosa/routes_api_python.git
$ cd routes_api_python
$ mkvirtualenv routes-api-dev
$ pip install -r requirements.txt$ python manage.py db upgrade
$ python run.pyThis endpoint lists all routes in the database.
$ curl -i https://routes-api-python-prod.herokuapp.com/routes{
"routes": [
{
"destination_point": "B",
"distance": 10,
"origin_point": "A",
"uri": "/routes/1"
},
{
"destination_point": "C",
"distance": 20,
"origin_point": "A",
"uri": "/routes/2"
},
{
"destination_point": "D",
"distance": 15,
"origin_point": "B",
"uri": "/routes/3"
},
{
"destination_point": "D",
"distance": 30,
"origin_point": "C",
"uri": "/routes/4"
},
{
"destination_point": "E",
"distance": 50,
"origin_point": "B",
"uri": "/routes/5"
},
{
"destination_point": "E",
"distance": 30,
"origin_point": "D",
"uri": "/routes/6"
}
]
}This endpoint returns a route.
$ curl -i https://routes-api-python-prod.herokuapp.com/routes/1{
"route": {
"destination_point": "B",
"distance": 10,
"origin_point": "A",
"uri": "/routes/1"
}
}This endpoint creates a new route.
| Name | Type | Description | Example |
|---|---|---|---|
| origin_point | string | The point of origin | "A" |
| destination_point | string | The point of destination | "D" |
| distance | integer | The vehicle's autonomy | 10 |
$ curl -i -H "Content-Type: application/json" -X POST https://routes-api-python-prod.herokuapp.com/routes '{"origin_point":"A","destination_point":"D","distance":10}'{
"route": {
"destination_point": "D",
"distance": 10,
"origin_point": "A",
"uri": "/routes/1"
}
}This endpoint updates a route.
| Name | Type | Description | Example |
|---|---|---|---|
| origin_point | string | The point of origin | "A" |
| destination_point | string | The point of destination | "D" |
| distance | integer | The vehicle's autonomy | 10 |
$ curl -i -X PUT -H "Content-Type: application/json" https://routes-api-python-prod.herokuapp.com/routes/1 -d '{"destination_point": "B"}'{
"route": {
"destination_point": "B",
"distance": 10,
"origin_point": "A",
"uri": "/routes/1"
}
}This endpoint deletes a route.
$ curl -X DELETE https://routes-api-python-prod.herokuapp.com/routes/1{
"result": true
}This endpoint calculates the cost based on distance, autonomy and fuel_price.
| Name | Type | Description | Example |
|---|---|---|---|
| origin_point | string | The point of origin | "A" |
| destination_point | string | The point of destination | "D" |
| autonomy | integer | The vehicle's autonomy | 10 |
| fuel_price | float | The fuel price | 2.5 |
$ curl -i -H "Content-Type: application/json" -X POST https://routes-api-python-prod.herokuapp.com/routes/calculate-cost -d '{"origin_point":"A","destination_point":"D","autonomy":10,"fuel_price":2.5}'{
"cost": 6.25,
"path": "A B D"
}python tests.pyThank you! :-)