Build simple Rest API using Spring Boot by implementing TDD.
Using Maven as dependency management, Mockito an JUnit as for testing extension and H2 as in-memory database.
Create test case for each layer (persistence, service, controller).
Using Codecov for coverage, TravisCI CircleCI for CI/CD and Docker for containerisation.
Before using this app, you need to prepare several things listed below. If you're able to run all these commands below, you're good to go 🥳
- Installed Java
java -version
- Maven
mvn -v
- Git
git --version
- Docker
docker version
To run this project, you have 3 options :
-
Run in you local
- Clone this repository
- You can run test and build the project by running
mvn clean package
- Start the app by typing
mvn spring-boot:run
from the root project directory to start the application. - Since we're using H2 as our in-memory database, you can launch the console by visiting http://localhost:8080/h2-console
-
Run using docker
- First, pull the docker image
docker pull mariesto/book-reservation-spring-boot
- Make sure it's already pulled
docker image ls
- Run the docker
docker run -p 8080:8080 book-reservation-spring-boot
- Now you can use the API as you wish
- First, pull the docker image
-
Save the best for the last (Play with Docker) 🤩
- You don't need docker installed in your local to use this, but you need to create your Docker Hub account first.
- Then you can visit this page https://labs.play-with-docker.com/
- In the terminal you can just run
docker run -p 8080:8080 mariesto/book-reservation-spring-boot
- Now you can click on the “Open Port” button and type in 8080
- Adjust the URL with
/api/v1/books/
and there you go 💥 - You can also visit this page for reference https://docs.docker.com/get-started/04_sharing_app/#run-the-image-on-a-new-instance
You can check the API documentation by run this application and hit http://localhost:8080/swagger-ui.html
This project related to article in medium : https://medium.com/easyread/interact-with-docker-b7f99e7ca26c