ddcprg / prime-number-service

REST service that generates prime numbers
Apache License 2.0
1 stars 0 forks source link

Prime Number generator

Build Status Coverage Status GitHub license

This sample application shows how to write a RESTful service with Spring Boot.

Overview

This application exposes an endpoint in http://127.0.0.1:9000/primes that can be used to retrieve all prime numbers up to the given value.

The API is documented with Swagger and the UI can be accessed on http://127.0.0.1:9000/swagger-ui.html.

The Spring Actuator can be accessed on http://127.0.0.1:9001/actuator.

The application also exposes a series of metrics that can be retrieved using a JMX console.

How to compile

Just run the following command on the project root:

./mvnw clean package

To execute the binary in the shell type:

java -jar ./prime-number-service-ws/target/prime-number-service-ws-0.1.2-SNAPSHOT.jar

Hit the endpoint

In order to access the service you must hit the endpoint http://127.0.0.1:9000/primes/{number} where number is the value up to which you want to generate prime numbers. You can also add the query parameter algorithm to choose from the set of primer number verification algorithms available:

Docker image

You can build a Docker image by activating the Maven profile docker. This profile will build and tag the image, during the Maven package phase, and push it, during the Maven deploy phase, to the local Docker Registry using the project version to tag the image. Make sure you have Docker installed in your compiling machine.

To run the image issue this command:

docker run -p 127.0.0.1:$HOST_PORT:9000 --name $CONTAINER_NAME -t company/prime-number-service-docker:0.1.2-SNAPSHOT

This will create a new Docker container with name $CONTAINER_NAMEwhich exposes the local port $HOST_PORT.