https://github.com/samkit-jain/musique-api
A simple REST API using flask-resful
https://github.com/samkit-jain/musique-api
flask-restful python rest-api
Last synced: over 1 year ago
JSON representation
A simple REST API using flask-resful
- Host: GitHub
- URL: https://github.com/samkit-jain/musique-api
- Owner: samkit-jain
- License: mit
- Created: 2017-07-22T12:08:05.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-07-22T14:10:23.000Z (almost 9 years ago)
- Last Synced: 2025-01-17T15:39:53.532Z (over 1 year ago)
- Topics: flask-restful, python, rest-api
- Language: Python
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# musique-api
A simple REST API using [flask-resful](https://github.com/flask-restful/flask-restful)
# How To Use
1. Open terminal
1. ```cd path/to/api.py```
1. ```python3 api.py```
1. Open another terminal
1. For POST request: ```curl http://localhost:5000/v1/tracks/23 -d "id=23&title=title23&rating=9.9&genres=12&genres=3" -X POST -v```
1. For GET request: Open http://localhost:5000/v1/tracks in your browser
# Usage
List all genres
HTTP GET to http://localhost:5000/v1/genres
```json
{
"count": 3,
"results": [
{
"id": 1,
"name": "rock"
},
{
"id": 2,
"name": "metal"
},
{
"id": 3,
"name": "indie"
}
]
}
```
Get single genre record
HTTP GET to http://localhost:5000/v1/genres/1 #here 1 in genres/1 is the ID of the genre
```json
{
"id": 1,
"name": "rock"
}
```
Edit genre record
HTTP POST to http://localhost:5000/v1/genres/1
```json
{
"id": 1,
"name": "pop"
}
```
Create new genre
HTTP POST to http://localhost:5000/v1/genres
```json
{
"name": "edm"
}
```
List all tracks
HTTP GET to http://localhost:5000/v1/tracks
```json
{
"count": 2,
"results": [
{
"id": 1,
"title": "Numb",
"rating": "9.5",
"genres": [
{
"id": 1,
"name": "rock"
}
]
},
{
"id": 2,
"title": "Hey mama",
"rating": "5.9",
"genres": [
{
"id": 4,
"name": "edm"
},
{
"id": 5,
"name": "house"
}
]
}
]
}
```
Search track
HTTP GET to http://localhost:5000/v1/tracks?title=Hey
```json
{
"count": 1,
"results": [
{
"id": 2,
"title": "Hey mama",
"rating": "5.9",
"genres": [
{
"id": 4,
"name": "edm"
},
{
"id": 5,
"name": "house"
}
]
}
]
}
```
Get single track record
HTTP GET to http://localhost:5000/v1/tracks/2
```json
{
"id": 2,
"title": "Hey mama",
"rating": "5.9",
"genres": [
{
"id": 4,
"name": "edm"
},
{
"id": 5,
"name": "house"
}
]
}
```
Edit track
HTTP POST to http://localhost:5000/v1/tracks/1
```json
{
"id": 1,
"title": "new title",
"rating": 4.5,
"genres": [2]
}
```
Add track
HTTP POST to http://localhost:5000/v1/tracks
```json
{
"title": "new title",
"rating": 9.5,
"genres": [1, 4]
}
```