Skip to content

A simple example of a REST API using SpringBoot + MongoDB + Docker 📊

License

Notifications You must be signed in to change notification settings

lironmo/springboot-rest-api-mongodb

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Campaigns REST API example

This code is part of your Home Assignment. the code is a simple example how you can use spring boot + mongodb + docker to create a rest api.

Technology stack:

  • Spring Boot
  • Spring Data
  • MongoDB
  • Log4j2 (instead of logback)
  • Docker
  • Swagger 2 (api documentation)
  • CORS filter
  • Unit Tests
  • Integration Tests

System requirements

  • JDK 11
  • Maven
  • Docker

API documentation

This example uses Swagger 2. Access http://localhost:8080/swagger-ui.html to check the documentation.

Build and run application

The file docker-compose.yml contains all the necessary settings to configure the environemnt. As this is a very simple application, we will basically have only two containers/services:

  • the rest api and the database.

If you want to build or rebuild services to include any code changes in the docker image(s), run docker-compose build.

To start all the services, you need to run docker-compose up (use -d to run in detached mode).

The docker image for the rest api application service is defined by the file Dockerfile using multi stages in order to build and execute the application.

If you prefer not to use docker, you can manually build and generate the executable file with mvn clean package and then run the maven spring boot plugin (mvn spring-boot:run) or directly the java command java -jar <jar file location>.

Do not forget to set the required environment variables for the application.properties. You must be running an instance of MongoDB server.

The rest api application will be available at http://localhost:8080.

Enjoy!

About

A simple example of a REST API using SpringBoot + MongoDB + Docker 📊

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 98.3%
  • Dockerfile 1.3%
  • JavaScript 0.4%