dev-resources.site
for different kinds of informations.
SpringBoot WebFlux Annotation-based RestAPIs
SpringBoot WebFlux Annotation-based 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 Annotation-based restful APIs.
Related posts:
- SpringBoot WebFlux Functional RestAPIs
- Reactor β Simple Ways to create Flux/Mono
- Spring WebClient with Spring Webflux | SpringBoot 2
- SpringBoot WebFlux Test
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
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 Annotation-based.
For starting with WebFlux, SpringBoot supports a collection dependency: spring-boot-starter-webflux
.
Sample code:
@RestController
@RequestMapping(value="/api/customer")
public class RestControllerAPIs {
@GetMapping("/")
public Flux getAll() {
...
}
@GetMapping("/{id}")
public Mono getCustomer(@PathVariable Long id) {
...
}
}
-
reactor.core.publisher.Flux
: is a standardPublisher
representing a reactive sequence of 0..N items, optionally terminated by either a success signal or an error. -
reactor.core.publisher.Mono
:Mono
is a specializedPublisher
that emits at most single-valued-or-empty result.III. Practice
In the tutorial, We create a SpringBoot project as below:
Step to do:
- Create SpringBoot project
- Create data model
- Implement Spring WebFlux APIs
- Run and check results
1. Create SpringBoot project
Using SpringToolSuite, create a SpringBoot project withReactive Web
dependency:
Check pom.xml
after creating:
More at:
SpringBoot WebFlux Annotation-based RestAPIs
Featured ones: