Skip to content

Music Library RESTful API (Manchester Codes Project)

Notifications You must be signed in to change notification settings

invertostew/music-library

Repository files navigation

MCR Codes Music Library

This is my music library project for Manchester Codes as part of the Backend module.

Description

The main purpose of this project is to learn how to design and implement an API which can perform CRUD operations on a database.

Features

Use RESTful routes to perform CRUD operations to store and manage your favourite music artists in a database.

Requirements

  • Node JS - to run the application.

Application Dependencies

  • Express - to set up the server and manage routes and responses.
  • MySQL2 - to work with the MySQL database engine.

Development Dependencies

  • Nodemon - to run the 'npm start' script
  • Dotenv - to store environment variables
  • Mocha - testing framework
  • Chai - assertion library
  • SuperTest - http assertions with async/await

Getting Started

  • docker pull bbatm9/music_library_mysql more info: DockerHub
  • docker run -d -p <OUTSIDE_PORT>:<INSIDE_PORT> --name <NAME> -e MYSQL_ROOT_PASSWORD=<PASSWORD> <IMAGE_NAME>.
  • Execute the git clone command on this repository.
  • cd into the repository directory.
  • npm install to install dependencies.
  • touch .env or manually create a .env file in the project root.
    • add the following:
    • DB_HOST=<YOUR_DB_HOST>
    • DB_USER=<YOUR_DB_USER>
    • DB_PASSWORD=<YOUR_PASSWORD>
    • DB_PORT=<YOUR_DB_PORT>
    • DB_NAME=<YOUR_DB_NAME>
    • PORT=<YOUR_APP_PORT>
  • npm start to start the server.
  • touch .env.test or manually create a .env.test file in the project root with the same values as above (except you should use a different DB_NAME) if you want to run the tests using npm test.

Documentation

Artists

HTTP Verb Route Example Request Body
GET /artists N/A
GET /artists/:artistId N/A
POST /artists {"name": "Some Artist", "genre": "Some Genre"}
PATCH /artists/:artistId {"name": "Updated Artist"} (options: name, genre)
DELETE /artists/:artistId N/A
POST /artists/:artistId/albums {"name": "Some Album", "year": "2022", "artist_id": "1"}

Albums

HTTP Verb Route Example Request Body
GET /albums N/A
GET /albums/:albumId N/A
PATCH /albums/:albumId {"name": "Updated Album"} (options: name, year, artist_id)
DELETE /albums/:albumId N/A

Testing

Built using a TDD approach. Tests are focused on integration testing. Each route/controller was first written as a failing test, which was then built out as per the tests, and later refactored and tested again.

All tests are located inside of the __tests__ directory.

If you wish to run the tests for yourself, you can install Mocha by running npm install and from there you can run the tests by running npm test.

I also used Insomnia to send requests to my RESTful API endpoints as documented above.

Insomnia API Testing Passing Tests!

About

Music Library RESTful API (Manchester Codes Project)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published