The Spring reactive web framework uses Webflux to facilitate Reactive functional endpoints. In this video, learn how to leverage Webflux in this project.
- [Instructor] Let's dive in to how we are leveraging Spring WebFlux to create a rest API. We will start by taking a look at the differences between Spring WebFlux and Spring MVC. By default, WebFlux is non blocking from top to bottom. It uses Netty instead of Tomcat as a web server, and it replaces the old Servlet API, with a Project Reactor based Spring Web API. While Spring WebFlux internally is very different from Spring MVC, you can use WebFlux in a similar manner with Spring MVC annotations. Recall that we wanted to create a series of endpoints to allow for the following: creating a new reservation, getting a reservation by ID, updating an existing reservation, and deleting an existing reservation. Now let's take a look at how one of those endpoints actually maps to some actual Spring WebFlux code. First, we use a GetMapping annotation, and pass in the URI of the string parameter. Then, we return a mono that emits a reservation as the return type. Then we capture the ID as a parameter using the path variable annotation. And finally, we leverage our service implementation to perform this lookup. So we can see that you can use all the same mappings from Spring MVC, that you may be familiar with. The main difference is we return Spring Reactive Publishers instead of a response entity. Diving a bit more into the controller layer, let's take a look at more details. A RestController annotation is a composed annotation that gives you both the controller and response body annotations. This allows for auto-registering of bean definitions. Also, this marks the controller as a web component, so that component scanning can add it to the Spring application context. The controller will leverage the reactive ServerHttpRequest and response, and finally, the JSON request body on incoming requests will be exposed as a flux that emits a data buffer. If you ever want to learn more about specific annotations, the Spring docs are very comprehensive. Clicking into each annotation and composed annotations will help you learn a lot more about the internals of Spring if you are interested.
- Benefits of using reactive programming with Angular and Spring
- Bootstrapping your Spring Boot app
- Building a reactive Spring REST API
- Creating and testing a WebFlux GET endpoint
- Building a front-end app with Angular
- Using and configuring reactive Spring Data
- Using a REST API GET request
- Unit testing with Spring Boot and Angular