

Consequently, thanks to using the Routes DSL along with Kotlin coroutines, we have fluent and concise endpoint definitions.

This is all we need to set up a simple REST controller. (it’s better to leave it in the build directory) The api-config. The outputDir is where the generated code will be placed. Not much changed compared to the controller except request and response types. If we analyze the task, we find: The generator is spring to be compatible with our spring-boot application The inputSpec is the openapi file that the code will be generated from. We should note that we’ve used suspending functions for defining the ProductsHandler class. ?: ServerResponse.notFound().buildAndAwait() The real benefit of Spring boot is when you create large web or standalone apps. Spring Boot is an overkill for such things. Additionally, reactive relational drivers are available for PostgreSQL and Microsoft SQL.Īt first, let’s implement a simple repository using the reactive approach: ProductRepository(private val client: DatabaseClient) The real objective of Spring Boot is not to write very basic programs like hello world. Our data store will be powered by the in-memory H2 database. Simply put, R2DBC is an API specification that declares a reactive API to be implemented by database vendors. Let’s start with the reactive relational database client. Next, we’ll add R2DBC dependencies to support reactive database access: įinally, we’ll add the Kotlin core and coroutines dependencies: So we need to include this dependency in our pom.xml: Next, as we’re relying on WebFlux for asynchronous processing, it’s very important to use spring-boot-starter-webflux instead of spring-boot-starter-web. Let’s use these versions, including Spring 5.2 via Spring Boot:
