0

Can I use new Kotlin DSL for setting up routing, for example as in :

router {
    ("/blog" and accept(TEXT_HTML)).nest {
        GET("/", fooHandler::findAllView)
        GET("/{slug}", fooHandler::findOneView)
    }
    ("/api/blog" and accept(APPLICATION_JSON)).nest {
        GET("/", barHandler::findAll)
        GET("/{id}", barHandler::findOne)
    }
}

with non-reactive web part? In the sense that underlying database will be Postgres and non Reactive servlet based application server so I do not want/need to use Flux or Mono for return types of barHandler or repository functions. But I do like new router DSL when used with Kotlin and it is more powerful than annotation based @RequestMapping and easier to get a grasp of all the app routes.

Saša Šijak
  • 8,717
  • 5
  • 47
  • 82
  • what do you mean by "non-reactive web part" a Spring MVC application? – Brian Clozel Oct 23 '17 at 11:50
  • @BrianClozel Think of like using Spring-WebMVC but with Kotlin functional DSL for writing up the router and not using annotations for it. All examples say that you can use DSL and annotations for WebFlux, but never mention if it is the same for WebMVC or we are stuck with just annotations there? – Saša Šijak Oct 23 '17 at 11:58
  • @SašaŠijak you could use a non-spring web framework (while keeping all the spring parts that you want). Examples of such frameworks are: Ktor, Javalin, and (my favorite, despite no websockets) http4k – pabl0rg Oct 23 '17 at 23:26
  • @pabl0rg I know that, but my question is if I could use this particular part of WebFlux package with WebMVC – Saša Šijak Oct 24 '17 at 08:25

1 Answers1

3

The DSL in your example is part of Spring WebFlux, which is the "reactive" thing you speak of. In this official blog post, the functionality is being introduced as "Spring WebFlux functional DSL".

The DSL entry point router is defined in the package org.springframework.web.reactive.function.server which also verifies what I said earlier. You can have a look at it on GitHub.

What you can use with traditional Web MVC though: The Functional bean declaration DSL that is used to define your application beans in a way that looks as follows:

beans {
    bean<Foo>()
    bean { Bar(ref()) }
}
s1m0nw1
  • 76,759
  • 17
  • 167
  • 196
  • I confirm it is not possible to use the Kotlin router DSL with Spring MVC which only supports the annotation-based programming model, not the functional one. – Sébastien Deleuze Oct 25 '17 at 08:29