Ktor 2.0: Should you apply @KtorDsl to a custom pl...
# ktor
h
Ktor 2.0: Should you apply @KtorDsl to a custom plugin? To the variable
@KtorDsl val myPlugin = createRouteScopedPlugin("myPlugin, ::Config) {}
AND to
@KtorDsl class Config
too?
If I apply the annotation, the implicit parameter does not work, and I need to add
this@routing.install
and
this@routing.get
...
a
@Rustam Siniukov
r
can you post a code snippet with example, please?
Copy code
@KtorDsl
val RateLimit = createRouteScopedPlugin("RateLimit, ::Config) {}

@KtorDsl
class Config

routing {
  get {
    call.respondText { "42" }
  }
  route("/login") {
    this@routing.install(RateLimit) {
      this@route.get {
        call.respondText { "/login called" }
      }
    }
  }
}
r
but
KtorDsl
has
@Target(AnnotationTarget.CLASS, AnnotationTarget.TYPEALIAS, AnnotationTarget.TYPE, AnnotationTarget.FUNCTION)
you can’t apply it to
val RateLimit = createRouteScopedPlugin("RateLimit, ::Config) {}
h
Oh, I simplified the sample too much. In my plugin, I used a function:
@KtorDsl fun RateLimit(requiredParameter) = createRouteScopedPlugin(...)
. But in the end,
install
works without explicit
this
. But
get
does not. At least the docs are wrong.