Skip to content

fernandoferreiratbe/product-ms

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

75 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Product Micro Service

The goal of this project is to implement a RESTfull API, following Leonard Richardson maturity model.

  • Level 0
  • Level 1 - Resources
  • Level 2 - HTTP Verbs
  • Level 3 - HATEOAS (Hypertext As The Engine Of Application State)

There are three ways to start API. Choose One and go ahead

  • Using Maven Tool in test environment
  • By Java command line in production environment
  • Through Docker Image / Container in production environment

Starting application in development mode

To start the application using Maven build tool run the command below:

$ mvn spring-boot:run -Dspring-boot.run.profiles=test

Note: Running application with test profile.

Starting application in production mode by command line

To start the application using jar package run the below commands:

$ cd <path_to_project_root_directory>
$ mvn clean package
$ java -jar -Dspring.profiles.active=prod -DPRODUCT_MS_DATABASE_URL=jdbc:h2:mem:product_ms -DPRODUCT_MS_DATABASE_USERNAME=sa -DPRODUCT_MS_DATABASE_PASSWORD=  target/product-ms.jar

Starting application through Docker Image/Container in production mode

Create the Docker image

$ docker build -t fferreira/product-ms .

Verify whether docker image has been generated

$ docker images

Create Docker container and run application through it

$ docker run --name fferreira_product_ms -p 9999:9999 -e SPRING_PROFILES_ACTIVE=prod -e PRODUCT_MS_DATABASE_URL='jdbc:h2:mem:product_ms;' -e PRODUCT_MS_DATABASE_USERNAME='sa' -e PRODUCT_MS_DATABASE_PASSWORD='' fferreira/product-ms

Check whether container is running

$ docker ps

Stop container

$ docker stop fferreira_product_ms

Start a container already created

$ docker start fferreira_product_ms

Access API documentation

To access the api documentation uses the url below after start application.

URL: http://localhost:9999/swagger-ui.html

API health

To monitor API health, send a get to the url below:

URL: http://localhost:9999/actuator

The /actuator resource exposes a list of another resources regard to API details:

E.g:

JaCoCo test coverage

The below command will test application and generate the jacoco.exec binary file used by tools like Sonarqube.

$ mvn test

The jacoco.exec binary file is not readable by humans, so if you would like to get a report in other format (Example: HTML) run the below command.

$ mvn jacoco:report

Note: It is necessary generate jacoco.exec file before generate humans readable report.

PS: After generate the JaCoCo test coverage report, access it through the directory: /target/site/jacoco/index.html

About

Demo project created to prove some concepts

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published