Logo

dev-resources.site

for different kinds of informations.

SpringBoot WebFlux Functional RestAPIs

Published at
5/3/2021
Categories
springboot
webflux
functional
restapis
Author
loizenai
Author
8 person written this
loizenai
open
SpringBoot WebFlux Functional RestAPIs

https://grokonez.com/spring-framework/spring-webflux/springboot-webflux-functional-restapis

SpringBoot WebFlux Functional RestAPIs

Reactive programming is about non-blocking applications. And Spring Framework 5 includes a new spring-webflux module, supports Reactive Streams for communicating backpressure across async components and libraries. So in the tutorial, JavaSampleApproach will guide you through the steps for creating a SpringBoot WebFlux Functional restful APIs.

Related posts:

I. Technologies

– Java: 1.8
– Maven: 3.3.9
– Spring Tool Suite: Version 3.9.0.RELEASE
– Spring Boot: 2.0.0.M4
– Spring Boot Starter Webflux

II. Spring WebFlux Functional

Spring Framework 5.0 supports WebFlux with fully asynchronous and non-blocking and does NOT require the Servlet API(Unlike Spring MVC).

Spring WebFlux supports 2 distinct programming models:
– Annotation-based with @Controller
– Functional with Java 8 lambda style

In the tutorial, we will introduce WebFlux with Functional.
For starting with WebFlux, SpringBoot supports a collection dependency: spring-boot-starter-webflux.

With Spring WebFlux Functional, we use {HandlerFunctions, RouterFunctions} to develop.

1. HandlerFunctions

HandlerFunctions will handle incoming HTTP requests through ServerRequest, and return a Mono


@Component
public class CustomerHandler {
    
    ...
    
    public Mono getAll(ServerRequest request) {
        ...
        return ServerResponse.ok().contentType(MediaType.APPLICATION_JSON).body(customers, Customer.class);
    }
    
    ...
    
    public Mono putCustomer(ServerRequest request) {
        ...
        return responseMono
                .flatMap(cust -> ServerResponse.ok().contentType(MediaType.APPLICATION_JSON).body(fromObject(cust)));
    }

    ...
    
    public Mono deleteCustomer(ServerRequest request) {
        ...
        return responseMono
                .flatMap(strMono -> ServerResponse.ok().contentType(MediaType.TEXT_PLAIN).body(fromObject(strMono)));
    }
}

2. RouterFunction

RouterFunction handle all incoming requests. It takes a ServerRequest, and returns a Mono. If a request matches a particular route, a handler function is returned; otherwise it returns an empty Mono.

More at:

https://grokonez.com/spring-framework/spring-webflux/springboot-webflux-functional-restapis

SpringBoot WebFlux Functional RestAPIs

webflux Article's
24 articles in total
Favicon
Introducing Java Library for Backend Microservice Webflux (Reactor-core)
Favicon
Making reactive applications with a Kitten Care Example
Favicon
Reactive Programming applied to Legacy Services β€” A WebFlux example
Favicon
Getting Started with Spring WebFlux
Favicon
Implementing Soft Delete in Spring WebFlux with R2DBC
Favicon
Java library for developing backend with reactive programming
Favicon
How to Run an Asynchronous Task in Spring WebFlux Without Blocking the Main Response?
Favicon
How to Run a Method Asynchronously in a Reactive Chain in Spring WebFlux?
Favicon
Spring WebFlux Retry Mechanism
Favicon
Implementing Context Propagation in Reactive Programming Projects πŸ”„
Favicon
Ability to unlearn in Software: Reactive Programming
Favicon
Create DTO using get results from repository returns duplicate values in Spring Boot Reactive WebFlux
Favicon
Spring R2DBC, MariaDB, and JSON columns
Favicon
SpringBoot WebFlux Annotation-based RestAPIs
Favicon
SpringBoot WebFlux Functional RestAPIs
Favicon
Spring Webflux testing with Mockito
Favicon
A Short Example of Real-Time Event Streaming Using Spring WebFlux
Favicon
Global Error Handling In Webflux (Reactive World)
Favicon
Spring Webflux - Reactive Java Applications - Part 2
Favicon
Building an URL Shortening API with Spring WebFlux (and a lot of supporting cast)
Favicon
Spring Webflux - Reactive Java Applications - Part 1
Favicon
Spring Webflux - Aplicaçáes reativas em Java - Parte 1
Favicon
KVision v2.0.0 - with Bootstrap 4, Spring Webflux and lots of other improvements
Favicon
Sending Multipart Form Data Using Spring WebTestClient

Featured ones: