An Express.js API that interacts with a sequelize database via CRUD requests to store and interact with reader and book information.
Sequelize uses MySQL dialect for tests and Postgres for production.
Implements Test-Driven development using Mocha and Chai.
Created as part of the Manchester Codes full-stack web development boot-camp.
App hosted on Render at https://book-library-f9gi.onrender.com.
$ npm i
If you have Docker installed, To set the database up, pull and run a MySQL image with:
$ docker run -d -p 3307:3306 --name book_library_mysql -e MYSQL_ROOT_PASSWORD=password mysql
You will need to create a file to store your environment variables. These credentials allow you to connect to the database. Two environments will need to be created, one for production and one for testing.
Create a .env
file in the root of the repo with the following values:
DB_PASSWORD=password
DB_NAME=book_library
DB_USER=root
DB_HOST=localhost
DB_PORT=3307
Create a .env.test
file in the root of the repo with the following values:
DB_PASSWORD=password
DB_NAME=book_library_dev
DB_USER=root
DB_HOST=localhost
DB_PORT=3307
To run the server use:
$ npm start
To run all tests use:
$ npm test
To only run unit tests use:
$ npm run unit-test
To run Prettier use:
$ npm run prettier
? In Schema represents optional field
Method | Route | Description | Schema (JSON) |
---|---|---|---|
POST | /readers | Creates new reader | { |
GET | /readers | Returns all readers | N/A |
GET | /readers/{readerId} | Returns reader of specified ID | N/A |
PATCH | /readers/{readerId} | Updates reader with specified ID | { |
DELETE | /readers/{readerId} | Deletes reader with specified ID | N/A |
Method | Route | Description | Schema (JSON) |
---|---|---|---|
POST | /books | Creates new book | { |
GET | /books | Returns all books and associated genres and authors | N/A |
GET | /books/{bookId} | Returns book of specified ID and associated genre and author | N/A |
PATCH | /books/{bookId} | Updates book with specified ID | { |
DELETE | /books/{bookId} | Deletes book with specified ID | N/A |
Method | Route | Description | Schema (JSON) |
---|---|---|---|
POST | /authors | Creates new author | { |
GET | /authors | Returns all authors and associated books and genres | N/A |
GET | /authors/{authorId} | Returns author of specified ID and associated books and genres | N/A |
PATCH | /authors/{authorId} | Updates author with specified ID | { |
DELETE | /authors/{authorId} | Deletes author with specified ID | N/A |
Method | Route | Description | Schema (JSON) |
---|---|---|---|
POST | /genres | Creates new genre | { |
GET | /genres | Returns all genres and associated books and authors | N/A |
GET | /genres/{genreId} | Returns genre of specified ID and associated books and authors | N/A |
PATCH | /genres/{genreId} | Updates genre with specified ID | { |
DELETE | /genres/{genreId} | Deletes genre with specified ID | N/A |
Created by Perry Baran.