A RESTful web service to managing ToDo items. ToDo items are stored in a database. The underlying implementation is based on Spring Boot built by Gradle. The provided Jenkinsfile
defines a build pipeline definition for creating, pushing and deploying a Docker image of the application.
Execute the task bootRun
with the Gradle Wrapper command to bring up the service. Optional arguments can be provided e.g. the server port. The following example starts the application on port 9090.
$ ./gradlew bootRun --args='--server.port=9090'
You can activate a profile by passing in the relevant environment. At the moment dev
and prod
is supported. The default profile uses a H2 database. The dev
profile assumes the usage of a PostgreSQL database for development purposes. The prod
profile is used for production environments.
The following example uses the development profile.
$ ./gradlew bootRun --args='--spring.profiles.active=dev'
Using the default profile:
$ docker run -p 8080:8080 -t bmuschko/todo-web-service
To use the production profile, pass in the SPRING_PROFILES_ACTIVE
environment variable:
$ docker run -e "SPRING_PROFILES_ACTIVE=prod" -p 8080:8080 -t bmuschko/todo-web-service
Once the service is up and running, you can call the exposed CRUD endpoints.
Example command:
$ curl -X GET localhost:8080/todos
Example response:
[ { "id":1, "name":"Buy milk", "completed":false }, { "id":2, "name":"Pay bills", "completed":true } ]
Example command:
$ curl -X GET localhost:8080/todos/2
Example response:
{ "id":2, "name":"Pay bills", "completed":true }
Example command:
$ curl -X POST -H "Content-Type:application/json" -d '{ "name" : "Buy milk", "completed" : false }' localhost:8080/todos