/Spring-Webflux-Reactive-REST-API

Spring Webflux REST API with Reactive Mongo and tests.

Primary LanguageJavaMIT LicenseMIT

Spring Webflux Reactive REST API

A demo project to develop a REST API using Spring Webflux and Spring Reactive Mongo. The aim is to apply reactive programming paradigm in Java with Spring.

  • Test Driven Development is adopted in this project.
  • Both MVC and functional routes are used to handle requests.
  • MVC controllers handle the requests to the endpoints starting with api/v1 while functional routes deal with the requests to the endpoints starting with api/v2
  • MongoDb is used to persist data.
  • For the reactive mongo configurations and usage visit this blog page: going reactive with spring data
  • Mongo Express is used to manage database visually.
  • A docker-compose.yml file for containerization.
  • Using the command docker-compose up will handle creating container from the images.
  • Sensitive data related to database connection is kept in .env file in the original project, but here we have .env.example.
  • .env.example file is used just to represent how to create a .env file for this project. Create a file named .env and put the content similar to the .env.example so that your spring boot application and docker-compose.yml can see those variables.

Endpoints

The endpoints are as follows:

Endpoint Method Function
  • /api/v1/products
  • /api/v2/products
  • GET Fetch all products
  • /api/v1/products/{id}
  • /api/v2/products/{id}
  • GET Fetch product by id
  • /api/v1/products
  • /api/v2/products
  • POST Create a new product
  • /api/v1/products/{id}
  • /api/v2/products/{id}
  • PUT Update product by id
  • /api/v1/products/{id}
  • /api/v2/products/{id}
  • DELETE Delete product by id

    Mongo Express

    Mongo Express will run on "http://localhost:8081/". Mongo Express uses HTTP Basic Authentication. The default username is admin and the default password is pass (see: mongo express on gitHub). Under the collection called "product" we store the data as documents. When visiting "http://localhost:8081/db/productDB/product", we will see: image


    Postman

    As well as testing the app via code, functionality of the API is tested by using Postman: image