john
john

Reputation: 1767

Where to import Ktor Plugin "install" from

I just created a new Ktor project, but following the docs, I am unsure where to import Plugin "install" function.

import io.ktor.server.engine.*
import io.ktor.server.netty.*
import io.netty.handler.codec.DefaultHeaders

fun main() {
    embeddedServer(Netty, port = 8080, host = "0.0.0.0") {
        install(DefaultHeaders)
        install(CallLogging)
        install(Koin) {
            slf4jLogger()
            modules(helloAppModule)
        }
        configurePlugins()
        configureRouting()
    }.start(wait = true)
}

My IDE has several suggestions, none of which seem to resolve correctly. I am using Ktor version 2.0.0.

Upvotes: 0

Views: 1053

Answers (1)

Phil Dukhov
Phil Dukhov

Reputation: 88327

The problem is that you have incorrect Default headers import.

  1. Make sure you have it as dependency:

    implementation("io.ktor:ktor-server-default-headers:$ktor_version")
    
  2. Replace

    import io.netty.handler.codec.DefaultHeaders
    

    with

    import io.ktor.server.plugins.defaultheaders.*
    
  3. IDE should suggest you the following import for install:

    import io.ktor.server.application.*
    

Upvotes: 2

Related Questions