A small repository system for storing a wish list of music albums. The repository hosts two collections: albums for the wish list and users to be able to login and get personalized wish lists. The MusicBrainz API is used to be able to search for album information.
- Java 8+
- MySQL Server 8.0.22
- Apache HTTP Components 4.5.13
- GlassFish Jersey Containers 2.17
- GlassFish Jersey Media 2.17
- Jakarta XML Binding API 2.3.2
- JAXB Runtime 2.3.2
- JUnit 4.9
- Jackson Core 2.12.1
- Grizzly HTTP Server 2.2.5
- JSON.simple 1.1.1
- Clone the repository to your machine.
- With MySQL Workbench installed and opened, run the data.sql script in src/main/resources to create the required tables. The following steps can be done in your favorite IDE or the command line.
- Use Maven to install the required dependencies. Gradle is compatible but not supported.
- In src/main/java/com/spicecrispies/service, run Main.java to start the program.
Requests can be sent from a GUI or from software such as Postman or cURL. Note that the following examples are using localhost:8080 as the URI where your usage might be with a different URI.
The following represents a series of requests to log in to the API and add albums to a wish list.
This example is the POST request needed to register a user (with the 'username' and 'password' included as a URL encoded www form):
http://localhost:8080/RESTfulMusic/user/registerIt will return a 200 response if the registration was successful. To log in, another POST request is required, similar to the previous example but with this URL:
http://localhost:8080/RESTfulMusic/user/loginLogging out simply requires including the username as a form parameter:
http://localhost:8080/RESTfulMusic/user/logoutAdditionally, one extra method is included to validate a login session:
http://localhost:8080/RESTfulMusic/user/authenticationIt will return a 200 response if the session is still valid.
This GET request is used to query the MusicBrainz API for a particular album and artist:
http://localhost:8080/RESTfulMusic/album/search/Take%20Time/Russell%20HitchcockIt will return the following:
[
{
"artist": "Russell Hitchcock",
"id": "d32f200c-4ea9-4777-92d2-b579dd43cfe4",
"releaseYear": 2006,
"title": "Take Time"
}
]The following requests require authentication, otherwise the client will receive a 401 unauthorized response. The session key that a client gets when a successful login occurs must be included as a header with the key 'x-api-key'.
This POST request is used to add an album to a user's wish list. The album is sent as a JSON attachment.
http://localhost:8080/RESTfulMusic/albumThis DELETE request is used to delete the album with ID 7 from a user's wish list:
http://localhost:8080/RESTfulMusic/album/7To get the information of an album with a certain ID (in this case, ID 7) in a user's wish list, send this request:
http://localhost:8080/RESTfulMusic/album/7To get the information of all albums in a user's wish list, simply exclude the ID:
http://localhost:8080/RESTfulMusic/album