Sample backend API. The goal is to exercise key concepts using JAVA 14, Spring Boot, Junit 5.
Sample RESTful API to manage a book catalog.
-
Java 14
-
Spring Boot: Many guides on building restful services are provided there
-
Spring Start: Spring Initializer tool
-
RESTful communication with JSON resources
-
Database
- Local: h2 in memory database. Console is enabled for further details at: http://localhost:8080/h2-console
- Upper environments: Postgres
-
Infrastructure: to be defined
- JUnit, Mockito, RestAssured for testing
- ArchUnit to test your code design
- Gradle to manage your dependencies
- Docker
Locally the application is running with an H2 database and a volatile memory defined at:
- Navigate to your root application directory and then run:
$ ./gradlew bootRun- Run with specific profile
$ ./gradlew bootRun --args='--spring.profiles.active=PROFILE '- Build the application (please notice that the application name and version may vary):
$ ./gradlew build && java -jar build/libs/catalog-0.0.1-SNAPSHOT.jar- Generate the application docker image:
$ mkdir -p build/dependency && (cd build/dependency; jar -xf ../libs/*.jar)
$ docker build --build-arg DEPENDENCY=build/dependency -t catalog/my-next-book-docker .- Run the application:
$ docker run --name=books -d -p 8080:8080 catalog/my-next-book-docker- Alternatively you can override the Spring active profile by running the container with:
$ docker run -e "spring.profiles.active=PROFILE" --name=books -p 8080:8080 catalog/my-next-book-dockerThe application is then available on http://localhost:8080
- When it is running you can see in the list of containers, e.g:
$ docker ps- Stop the container:
$ docker stop booksLet's see how to
- Create volume to store data
$ docker create -v /var/lib/postgresql/data --name PostgresData alpine- Create database
$ docker run -p 5432:5432 --name postgres -e POSTGRES_PASSWORD=<define a password> -d --volumes-from PostgresData postgres