The Spring team has kept the same annotations for both Spring MVC and Spring WebFlux as these annotations are non-blocking. Therefore, you can use the same annotations we have used in previous chapters for creating REST controllers. There, the annotation runs on Reactive Core and provides a non-blocking flow. However, you, as the developer, have the responsibility of maintaining a fully non-blocking flow and maintaining the Reactive chain (pipeline). Any blocking calls in a Reactive chain would convert the Reactive chain into a blocking call.
Let's create a simple REST controller that supports non-blocking and Reactive calls:
xxxxxxxxxx
@RestController
public class OrderController {
@RequestMapping(value = "/api/v1/orders",
method = RequestMethod.POST)
public ResponseEntity<Order> addOrder(@RequestBody NewOrder
newOrder){
// …
}
@RequestMapping(value = "/api/v1/orders/{id}",
method = RequestMethod.GET)
public ResponseEntity<Order> getOrderById(@PathVariable("id")
String id){
// …
}
}