Creating a reactive file controller
With our reactive image service in place, we can start to work on the reactive file controller.
For starters, let's create a HomeController
as shown here:
@Controller public class HomeController { private static final String BASE_PATH = "/images"; private static final String FILENAME = "{filename:.+}"; private final ImageService imageService; public HomeController(ImageService imageService) { this.imageService = imageService; }
The preceding code can be described as follows:
@Controller
: This indicates that it is a web controller, and will be registered by Spring Boot to handle web requests.BASE_PATH
: This is a static string used to define the base of many routes.FILENAME
: This is a pattern for filenames where the ".
" is included. Otherwise, Spring WebFlux will use the suffix as part of content negotiation (for example,.json
would try to fetch a JSON response, while.xml
would try to fetch an XML...