Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mdsrosa/routes_api_python
Python version of http://github.com/mdsrosa/routes_api. Live at https://routes-api-python-prod.herokuapp.com
https://github.com/mdsrosa/routes_api_python
Last synced: 14 days ago
JSON representation
Python version of http://github.com/mdsrosa/routes_api. Live at https://routes-api-python-prod.herokuapp.com
- Host: GitHub
- URL: https://github.com/mdsrosa/routes_api_python
- Owner: mdsrosa
- License: mit
- Created: 2015-11-21T01:22:16.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2023-05-02T00:15:20.000Z (almost 2 years ago)
- Last Synced: 2024-11-21T00:44:33.621Z (3 months ago)
- Language: Python
- Homepage:
- Size: 42 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Routes API
###### Python version of http://github.com/mdsrosa/routes_api[![Build Status](https://travis-ci.org/mdsrosa/routes_api_python.svg)](https://travis-ci.org/mdsrosa/routes_api_python) [![Coverage Status](https://coveralls.io/repos/mdsrosa/routes_api_python/badge.svg?branch=master&service=github)](https://coveralls.io/github/mdsrosa/routes_api_python?branch=master)
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
# Installation
###### **Considering you already have a Python development environment setup.**```bash
$ git clone https://github.com/mdsrosa/routes_api_python.git
$ cd routes_api_python
$ mkvirtualenv routes-api-dev
$ pip install -r requirements.txt
```### Running Locally
```bash
$ python manage.py db upgrade
$ python run.py
```# Endpoints
#### GET /routes
This endpoint lists all routes in the database.
#### cURL Example
```bash
$ curl -i https://routes-api-python-prod.herokuapp.com/routes
```
#### Response Example
```bash
{
"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"
}
]
}
```#### GET `/routes/pk`
This endpoint returns a route.##### cURL Example
```bash
$ curl -i https://routes-api-python-prod.herokuapp.com/routes/1
```##### Response Example
```bash
{
"route": {
"destination_point": "B",
"distance": 10,
"origin_point": "A",
"uri": "/routes/1"
}
}
```#### POST `/routes`
This endpoint creates a new route.#### Fields
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 Example
```bash
$ 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}'
```##### Response Example
```bash
{
"route": {
"destination_point": "D",
"distance": 10,
"origin_point": "A",
"uri": "/routes/1"
}
}
```#### PUT `/routes/pk`
This endpoint updates a route.#### Fields
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 Example
```bash
$ curl -i -X PUT -H "Content-Type: application/json" https://routes-api-python-prod.herokuapp.com/routes/1 -d '{"destination_point": "B"}'
```##### Response Example
```bash
{
"route": {
"destination_point": "B",
"distance": 10,
"origin_point": "A",
"uri": "/routes/1"
}
}
```#### DELETE `/routes/pk`
This endpoint deletes a route.##### cURL Example
```bash
$ curl -X DELETE https://routes-api-python-prod.herokuapp.com/routes/1
```##### Response Example
```bash
{
"result": true
}
```#### POST `/routes/calculate-cost`
This endpoint calculates the cost based on `distance`, `autonomy` and `fuel_price`.
#### Fields
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 Example
```bash
$ 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}'
```
##### Response Example
```json
{
"cost": 6.25,
"path": "A B D"
}
```# Testing
```bash
python tests.py
```Thank you! :-)