Handling AJAX calls on the server
To support the fact that we are now making an AJAX call, and not expecting a redirect, we need to make alterations on the server side.
For one thing, we need to change the image
microservice's CommentController
from being view-based to being a REST controller. Earlier in this book, it looked like this:
@Controller @EnableBinding(Source.class) public class CommentController { ... }
@Controller
marked it as a Spring WebFlux controller that was expected to return the HTTP redirect.
To tweak things for AJAX calls, update it to look like this:
@RestController @EnableBinding(Source.class) public class CommentController { ... }
By replacing @Controller
with @RestController
, we have marked this class as a Spring WebFlux controller with results written directly into the HTTP response body.
With that in place, we can now rewrite addComment
as shown here:
@PostMapping("/comments") public Mono<ResponseEntity...