Book Nook API

  • This is a REST API of a project called "Book Nook" made with Spring Boot + MySQL.
  • Authentication and Authorization is controlled via JWT.
  • Includes Unit testing of services via Junit and Integration testing of controllers via RestAssured + TestContainers (Docker).
  • Also, API documentation via the swagger and openAPI Springdocs package.
  • This project is inspired by Good Reads. An app that let the user have custom shelves with their favorite books and be able to review them.

Getting Started

  • These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
  • At the end is also what you will need to Dockerize the application and an initial MySQL DB.

Local

Prerequisites

- Java 17
- MySQL 8
- Maven
- Docker (for testing purposes) now also for Dockerization.

Installing

A step by step series of examples that tell you how to get a development env running

1 - Git clone the repository

$ git clone https://github.com/jfontdev/book-nook-spring.git

2 - Install the dependencies of the project

$ mvn clean install

3 - Create an empty MySQL DB

4 - Create an environment properties file called env.properties on the root of the project and fill the next list of properties from your MySQL DB also the JWT secret you want to use and the expiry time of the token in seconds.

DB_HOST=
DB_DATABASE=
DB_USERNAME=
DB_PASSWORD=
JWT_SECRET=
JWT_EXPIRE=

5 - Run the project, the first time Spring will generate the tables in your DB according to the models.

6 - Visit "http://localhost:8080/swagger-ui/index.html" to get a ui representation of the endpoints and schemas of our application. You can also get a JSON representation via "http://localhost:8080/v3/api-docs".

7 - Explore the different endpoints, register a user, log in and enjoy the app :)

Docker

Installing

A step by step series of examples that tell you how to get a development env running

1 - Git clone the repository

$ git clone https://github.com/jfontdev/book-nook-spring.git

2 - Create an environment file called .env on the root of the project and fill the next list of properties from your MySQL DB also the JWT secret you want to use and the expiry time of the token in seconds.

DB_HOST=
DB_DATABASE=
DB_USERNAME=
DB_PASSWORD=
JWT_SECRET=
JWT_EXPIRE=

3 - Run docker compose up to start the process of dockerization of the DB and application:

  • This will create two containers with the same network.
  • I will also create the database "book_nook" (If you use another DB name in the .env file, you will have to change the mysql_scripts -> db_init.sql file with the new name of the DB.)
  • It will create the table "books" and populate it with some data.
  • Get all the dependencies for the Spring app.
  • Run the app, the first time Spring will generate the tables in your DB according to the models.

4 - Visit "http://localhost:8080/swagger-ui/index.html" to get a ui representation of the endpoints and schemas of our application. You can also get a JSON representation via "http://localhost:8080/v3/api-docs".

5 - Explore the different endpoints, register a user, log in and enjoy the app :)

Running the tests

To run the tests use the maven test command to run them all.

$ mvn test

Built With

  • Spring Boot - The web framework used.
  • MySQL - The database used.
  • Maven - Dependency Management.
  • JJWT - Used to auth and authorize via JWT implementation in Java.
  • Junit - Used to do unit testing across the project.
  • RestAssured - Used to do integration testing of REST endpoints.
  • TestContainers - Used to containerize via docker our MySQL DB to run tests on it instead of our real DB.
  • Springdoc - Used to generate documentation of the REST API endpoints and schema.