Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Build Reactive REST APIs with Spring WebFlux – Part3

Photo by Chris Ried on Unsplash

In continuation of the last article, we will see an application to expose Reactive Rest Apis. In this application, we used,

  • Spring Boot with WebFlux
  • Spring Data for Cassandra with Reactive Support
  • Cassandra Database

Below is the high-level architecture of the application.

Let us look at the build.gradle file to see what dependencies are included to work with the Spring WebFlux.

In this application, I have exposed the below mentioned Apis. You can download the source code from GitHub.

Endpoint URI Response
Create a Product /product Created product as Mono
All products /products returns all products as Flux
Delate a product /product/{id} Mono
Update a product /product/{id} Updated product as Mono

The product controller code with all the above endpoints is given below.

As we are building Reactive APIs, we can build APIs with a functional style programming model without using RestController. In this case, we need to have a router and handler components as shown below.

So far, we have seen how to expose reactive REST APIs. With this implementation, I have done a simple benchmarking on reactive APIs versus the non-reactive APIs (built non-reactive APIs using Spring RestController) using Gatling. Below are the comparison metrics between the reactive and non-reactive APIs. This is not an extensive benchmarking. So, before adopting please make sure to do extensive benchmarking for your use case. 

The Gatling load test scripts are also available on GitHub for your reference. With this, I conclude the series of “Build Reactive REST APIs with Spring WebFlux“. We will meet on another topic. Till then, Happy Learning!!

This post first appeared on Smart Techie | My Thoughts, My Work, My Ideas, please read the originial post: here

Share the post

Build Reactive REST APIs with Spring WebFlux – Part3


Subscribe to Smart Techie | My Thoughts, My Work, My Ideas

Get updates delivered right to your inbox!

Thank you for your subscription