Skip to content

mdarwish/musicCollection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring Boot Music Collection REST Microservice

Build Restful CRUD API for a simple Music Collection application using Spring Boot, Mysql, JPA and Hibernate.

Prerequisites

  1. Java - 1.8.x

  2. Maven - 3.x.x

  3. Mysql - 5.x.x

Setup

1. Clone this repository

git clone --recursive https://github.com/mdarwish/musicCollection.git

2. Create Mysql database

create database music_repo

3. Run the seed database script "music_repo.sql" under the "data" folder in your MySQL client of choice

4. Change mysql username and password as per your installation

  • open src/main/resources/application.properties

  • change spring.datasource.username and spring.datasource.password as per your mysql installation

5. Build and run the app using maven Switch to the folder where you cloned the repository on your local machine and build the application

mvn clean install package

Then run it -

java -jar target/musicCollection-0.0.1-SNAPSHOT.jar

 - OR -

mvn spring-boot:run

The app will start running at http://localhost:9700. You can change the port by changing the "server.port" property in application.properties file.

Application Layout

alt text

Class diagram

alt text

Sample Sequence diagram

alt text

Explore Rest APIs

The app defines following CRUD APIs.

Create Endpoints

POST /collection/artist/new

POST /collection/artist/{artist_id}/album/new

POST /collection/artist/{artist_id}/album/{album_id}/song/new

Retrieve Endpoints

GET /collection/artists

GET /collection/albums

GET /collection/songs

Update Endpoints

PUT /collection/artist/{id}

PUT /collection/album/{id}

PUT /collection/song/{id}

Delete Endpoints

DELETE /collection/song/{Id}

DELETE /collection/album/{id}

DELETE /collection/artist/{Id}

Management Endpoints

GET /health

GET /info

GET /metrics

You can GET requests in the browser. Other verbs can be tested using SoapUI or any other rest client.

TODO

1. JUnit tests smaples Added in latest update

2. Spring REST Docs samples Added in latest update

3. UI (Not applicable)

Sample requests

```bash
//Retrieve all songs request
GET http://localhost:9700/collection/songs HTTP/1.1

//Retrieve all artists request
GET http://localhost:9700/collection/artists HTTP/1.1

//Retrieve all albums request
GET http://localhost:9700/collection/albums HTTP/1.1

//Retrieve all albums for specific artist
GET http://localhost:9700/collection/artist/14/albums HTTP/1.1

POST http://localhost:9700/collection/artist/new HTTP/1.1
content-type: application/json

{
    "name": "Cars"
}

//Add new album request
POST http://localhost:9700/collection/artist/18/album/new HTTP/1.1
content-type: application/json

{
    "name": "Panorama",
    "yearReleased": "1980"
}

//Update album request
PUT http://localhost:9700/collection/album/75 HTTP/1.1
content-type: application/json

{
    "name": "Panorama - live"
}

//Add new song request
POST http://localhost:9700/collection/artist/18/album/75/song/new HTTP/1.1
content-type: application/json

{
    "name": "Getting Through"
}

//Update song request
PUT http://localhost:9700/collection/song/36 HTTP/1.1
content-type: application/json

{
    "name": "Panorama",
    "created": "1980"
}

//Delete song request
DELETE http://localhost:9700/collection/song/37 HTTP/1.1

DELETE http://localhost:9700/collection/album/74 HTTP/1.1

DELETE http://localhost:9700/collection/artist/17 HTTP/1.1

Screen shots

Retrieving Artists

alt text

Retrieving Album by its ID

alt text

Adding a Song

alt text

Deleting a Song

alt text

Documentation sample

alt text

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published