Install all dependencies by running:
root:~$ pip install -r requirements.txt
Start the server by running api.py:
root:~$ python api.py
Note: By default the server will start on port 5000.
Testing can be carried out by running:
root:~$ python test_api.py
Returns json data about a single track.
-
URL
/track/:track_id
-
Method:
GET
-
URL Params
Required:
track_id=[integer]
-
Data Params
None
-
Success Response:
- Code: 200
Content:{"track": [{"id": "5", "title": "Paparazzi", "artist": "Lady GaGa", "duration": "199", "last_play": ' \ '"2016-02-23 08:24:37"}]}
- Code: 200
-
Error Response:
- Code: 404 NOT FOUND
Content:{\"message\": \"track 100000 doesn\'t exist\"}
- Code: 404 NOT FOUND
-
Sample Call:
Filters tracks by title their title.
-
URL
/track/filter_by_name
-
Method:
GET
-
URL Params
Required:
filter_text= [string]
-
Data Params
None
-
Success Response:
- Code: 200
Content:{ "tracks": [ { "id": "3667", "title": "I Get The Sweetest Feeling", "artist": "Jackie Wilson", "duration": "165", "last_play": "2018-05-17 14:05:28" } ] }
- Code: 200
-
Sample Call:
curl http://localhost:5000/tracks/filter_by_name/I%20Get%20The%20Sweetest%20Feeling
Adds a new track and returns json data about the track
-
URL
/track
-
Method:
POST
-
URL Params
Required:
None
-
Data Params
id=[integer]
title=[string]
artist=[string]
duration=[integer]
lastplay=[datetime]
-
Success Response:
- Code: 200
Content:{"track": [{"id": "1436", "title": "A new song!", "artist": "A New Artist", "duration": "259", "last_play": ' \ '"2018-02-23 08:24:37"}]}
- Code: 200
-
Error Responses:
- Code: 409 CONFLICT
Content:{"message": "track 1 already exists"}
- Code: 409 CONFLICT
-
Sample Call:
curl http://localhost:5000/tracks -d "id=4525&title=The Songs Name&artist=The Artists Name&duration=150&2018-05-17 16:56:21 new" -X POST -v
Returns last 100 played tracks (the latest first).
-
URL
/last_played
-
Method:
GET
-
URL Params
Required:
None
-
Data Params
None
-
Success Response:
- Code: 200
Content:{ "tracks": [ { "id": "394", "title": "Love Generation", "artist": "Bob Sinclar / Gary Nesta Pine", "duration": "172", "last_play": "2018-05-17 16:59:11" }, { "id": "583", "title": "Jus.....
- Code: 200
-
Sample Call:
Returns all artists along with the number of tracks they have and their most recently played track.
-
URL
/artists
-
Method:
GET
-
URL Params
Required:
None
-
Data Params
None
-
Success Response:
- Code: 200
Content:{ "tracks": [ { "artists": [ { "artist": "Belinda Carlisle", "plays": 3, "last_played_track": "Heaven Is A Place On Earth" },..
- Code: 200
-
Sample Call: