This project is a back-end service that drives a separate front-end application. It includes a database service that tracks songs that users have favorited through the front-end application. Users can also create playlists and add their favorite songs to a playlist. Song metadata comes from the MusixMatch API.
This application requires several technologies to be installed to your local machine. The following are required:
To install this application locally, take the following steps:
- Run
git clone git@github.com:DanielMulitauopele/play-api.git
in your terminal - Navigate to the newly created project directory
- Run
npm install
in your terminal to install the required node modules - In your terminal run
psql
to launch the PostgreSQL CLI - Run
CREATE DATABASE play;
for the development database, andCREATE DATABASE play_test;
for the test database. - Run
knex migrate:latest
to run the necessary migrations to get the tables up and running. - Run
npm test
to start the test suite. - Run
npm start
to start the server to view the application endpoints athttp://localhost:3000
.
Production
Development
This project was developed, tested, and published by Mike McKee and Daniel Mulitauopele.
There are two main endpoints for interacting with this API.
Returns all songs that have been favorited and added to the database.
Request
GET /api/v1/songs
Response
[
{
"id": 1,
"name": "We Are The Champions",
"artist_name": "Queen",
"genre": "Rock",
"song_rating": 84
},
{
"id": 2,
"name": "Sandstorm",
"artist_name": "Darude",
"genre": "Electronic",
"song_rating": 82
}
]
Returns a song with the specific given :id
.
Request
GET /api/v1/songs/1
Response
{
"id": 1,
"name": "We Are The Champions",
"artist_name": "Queen",
"genre": "Rock",
"song_rating": 84
}
If no song is found with given ID, the following is returned with a status 404.
{
"error": "Could not find song with id: 35"
}
Adds a song to the database with given parameters.
Request
POST /api/v1/songs
Content-Type: application/json
Body:
{ "name":"We Will Rock You", "artist_name": "Queen", "genre":"Rock", "song_rating":"90" }
Response
{
"songs": {
"id": 22,
"name": "We Will Rock You",
"artist_name": "Queen",
"genre": "Rock",
"song_rating": 90
}
}
All Fields Are Required! Song rating must be between 1 and 100.
If any fields are not given (artist name in this case), a 400 status code is returned with the following response.
{
"error": "Expected format: { name: <String>, artist_name: <String>, genre: <String>, song_rating: <Integer> }. You're missing a "artist_name" property."
}
Update a specific song with the given ID. ID field is required. You can specify all fields or just one.
Request
PATCH /api/v1/songs/1
Content-Type: application/json
Body:
{ "name":"We Will Rock Youuuu" }
Response
{
"songs": {
"id": 17,
"name": "We Will Rock Youuuu",
"artist_name": "Queen",
"genre": "Rock",
"song_rating": 90
}
}
If song with the given ID is not found, returns a 404 error with the following response.
{
"error": "Song with ID 500 not found"
}
Deletes the specific song with the given ID. ID field is required.
*Request
DELETE /api/v1/songs/1
Response
204 No Content
If song with the given ID is not found, returns a 404 error with the following response.
{
"error": "Song with ID 500 not found"
}
Retrieves all playlists with their songs if applicable.
Request
GET /api/v1/playlists
Response
[
{
"id": 1,
"playlist_name": "Super Cool Fun Jams",
"songs": [
{
"id": 1,
"name": "We Will Rock You",
"artist_name": "Queen",
"genre": "Rock",
"song_rating": 82
},
{
"id": 3,
"name": "Le Freak",
"artist_name": "Chic",
"genre": "Disco/Pop",
"song_rating": 82
}
]
},
{
"id": 2,
"playlist_name": "Summer Mix",
"songs": [
{
"id": 5,
"name": "Summertime",
"artist_name": "Childish Gambino",
"genre": "Rap",
"song_rating": 77
}
]
}
]
Adds a new playlist to the database. Field "playlist_name" is the only requirement.
Request
POST /api/v1/playlists
Content-Type: application/json
Body:
{ "playlist_name":"Summer Mix" }
Response
{
"playlist": {
"id": 4,
"playlist_name": "Summer Mix"
}
}
If no field "playlist_name" is given, returns a status 400 error.
{
"error": "Expected format: { playlist_name: <String> }."
}
Retrieves a specific playlist with given :playlist_id
and its songs.
Request
GET /api/v1/playlists/1/songs
Response
{
"id": 1,
"playlist_name": "Super Cool Fun Jams",
"songs":[
{
"id": 1,
"name": "We Will Rock You",
"artist_name": "Queen",
"genre": "Rock",
"song_rating": 82
},
{
"id": 3,
"name": "Le Freak",
"artist_name": "Chic",
"genre": "Disco/Pop",
"song_rating": 82
}
]
}
If given :playlist_id
is not found, a 404 error is returned with the following response.
{
"error": "Playlist with ID 500 does not exist"
}
Adds a given song with :id
to playlist with given :playlist_id
.
Request
POST /api/v1/playlists/1/songs/1
Response
{
"message": "Successfully added Who Let The Dogs Out? to Super Cool Fun Jams"
}
If song ID is not found or playlist ID is not found, a 404 status code is returned with the following responses.
{
"error": "Song with ID 500 does not exist"
}
{
"error": "Playlist with ID 500 does not exist"
}
Deletes a given song with :id
from playlist with given :playlist_id
.
Request
DELETE /api/v1/playlists/1/songs/1
Response
{
"message": "Successfully removed Who Let The Dogs Out? from Super Cool Fun Jams"
}
If song ID is not found or playlist ID is not found, a 404 status code is returned with the following responses.
{
"error": "Song with ID 500 does not exist"
}
{
"error": "Playlist with ID 500 does not exist"
}