https://kotlinlang.org logo
Join Slack
Powered by
# ktor
  • j

    Jay

    08/28/2025, 6:02 AM
    if i use OkHttp as my client, does it matter if i put my headers in the OkHttpConfig or in the defaultRequest {} block?
    h
    • 2
    • 1
  • a

    albrechtroehm

    08/28/2025, 9:12 AM
    Hey, anyone here maybe uses Selfie for snapshot-test https://github.com/diffplug/selfie and knows how to get around the limitation with coroutines that are in effect when using
    testApplication
    ?
  • d

    Dewan Tawsif

    08/28/2025, 12:58 PM
    Is there a way to force ktor to read from cache and fail if the request is not cached? In OkHttp I can set cache control to
    CacheControl.FORCE_CACHE
    to achieve this behavior.
    a
    • 2
    • 3
  • y

    Yoonho Aaron Kim

    08/29/2025, 5:48 AM
    I am an Android developer. I'm using Retrofit and had previously created and used interceptors for testing purposes. These interceptors would intercept cases difficult to reproduce in the actual production environment and force mock responses. I'm gradually migrating the app from Retrofit to Ktor. Therefore, I need an interceptor for Ktor that intercepts responses and replaces them with desired values. I've been researching this and asking GPT, Grok, and Gemini, but it's not working as intended. I understand I need to create a custom plugin. However, I couldn't achieve the desired result using onRequest or onResponse blocks. While I can intercept requests and trigger side effects, I can't actually return a response. I'm looking into transformResponseBody, but it also isn't working as intended. When I run very simple code like this, it throws an IllegalStateException.
    Copy code
    val ktorInterceptor = createClientPlugin("InterceptorPlugin") {
      transformResponseBody { response, content, requestedType ->
        content
      }
    }
    
    ...
    
    HttpClient(Android) {
      install(Logging) {
        logger = Logger.ANDROID
      }
    
      install(ktorInterceptor)
    }
    
    suspend fun getUser(): RespUser {
        return client.get(url).body()
    }
    
    -> java.lang.IllegalStateException: transformResponseBody returned io.ktor.utils.io.SourceByteReadChannel@7e05379 but expected value of type TypeInfo(RespUser (Kotlin reflection is not available))
    How can I resolve this? I also asked on the stackoverflow too
    s
    a
    j
    • 4
    • 5
  • m

    Mario Andhika

    08/29/2025, 9:18 AM
    The context menu item “Generate OpenAPI documentation for current module” is not generating anything on my project. But it works on a project that is freshly generated by the project wizard.
    a
    • 2
    • 1
  • y

    Yassine Abou

    08/30/2025, 12:18 PM
    Hi everyone, I'm very new to backend development, Ktor, and the Exposed framework. I'm working on a project and trying to migrate my database connection from the standard JDBC (with HikariCP) to R2DBC to learn more about reactive programming. Since I couldn't find many direct examples online for this specific setup, I used an AI assistant to help generate the code. Now, I'm not sure if the result is correct or follows best practices. I'd be really grateful if someone with more experience could take a look and give me some feedback. For context, I've posted the 'before' and 'after' versions of my code below for you to check.
    a
    • 2
    • 2
  • s

    skominas.ainis

    08/31/2025, 12:24 PM
    Could someone recommend some Ktor open-source repositories where I could find some best-practices how to use Ktor? Just looking to learn mostly the structure and how some problems are handled
    h
    • 2
    • 5
  • k

    k k

    08/31/2025, 2:21 PM
    I believe that Ktor always returns a status code. Is there a way to get the finalized status code? When using
    on(ResponseSent)
    , the status is nullable:
    Copy code
    on(ResponseSent) { call ->
      call.response.status() // => HttpStatusCode?
    a
    • 2
    • 7
  • a

    Arjan van Wieringen

    08/31/2025, 6:12 PM
    Hot reload is broken in 2 ways in latest stable Ktor release: • embeddedServer does not work at all with hot reload • staticResources result in 404 after reload, both in embeddedServer and EngineMain Finding out that these things did not work sent me on a nice investigation. I thought it was my project settings, but it happens in the default project from the project generator even. https://youtrack.jetbrains.com/issue/KTOR-8821/Hot-reload-broken-in-Ktor-3.2.3-in-2-ways
    a
    • 2
    • 1
  • a

    Alyona Chernyaeva

    09/01/2025, 7:55 AM
    Koog 0.4.0 is out! It comes with a new Ktor plugin that lets you put agents behind your API in minutes. Just install, configure providers, and call them from any route. Now the only thing left to decide is the name: the Ktor Koog plugin or the Koog Ktor plugin? 1️⃣ Ktor Koog plugin 2️⃣ Koog Ktor plugin
    1️⃣ 5
    2️⃣ 2
  • j

    jamshedalamqaderi

    09/01/2025, 10:45 AM
    I’m getting a build error when configuring the Ktor Darwin engine’s handleChallenge on iOS while using the Foundation constants
    NSURLSessionAuthChallengePerformDefaultHandling
    and
    NSURLSessionAuthChallengeUseCredential
    . The completionHandler’s first parameter (disposition) appears to have a mismatched expected type across targets/toolchains (Int vs Long), causing “Argument type mismatch” errors. https://github.com/JamshedAlamQaderi/appwrite-kmp/blob/eab65e933c0e794b686592559c1[…]iosMain/kotlin/com/jamshedalamqaderi/kmp/appwrite/Client.ios.kt
    K 1
    a
    • 2
    • 10
  • t

    Tiago

    09/01/2025, 2:06 PM
    Hey! I'm using Ktor for a web server (duh), and I happen to want to keep a lot of websocket connections open. I seem to be hitting some sort of limit at 3000 sockets, with more timing out. I can hold 100000~ websocket connections open on Bun (javascript runtime). Would you happen to have any tips on how to increase the number of websockets a ktor server can keep alive?
    c
    • 2
    • 37
  • s

    skominas.ainis

    09/02/2025, 4:46 PM
    Has anyone tried running Auto-Reload feature with HTMX or staticResources? For some reason it is not working for me. It catches the changes, but then the web-app is not working, even though Java process is still running. I'd need to debug it albeit more to find the culprit, but I wonder if someone had this issue? With "normal" Ktor server it is working fine. Only with HTMX setup it isn't
    a
    a
    h
    • 4
    • 17
  • s

    Stefan Oltmann

    09/04/2025, 11:25 AM
    How can I turn the logging for embedded Ktor Server in
    commonMain
    off? At start it logs this:
    Copy code
    [INFO] (io.ktor.server.Application): Application started in 0.0 seconds.
    [INFO] (io.ktor.server.Application): Responding at <http://127.0.0.1:49991>
    Even the macOS / mingW binaries log this at start. I want it to be completely silent. I think it comes from here: https://github.com/ktorio/ktor/blob/b7face18342805d8a0eb77bb711d72aea5cd49a3/ktor-[…]-core/common/src/io/ktor/server/engine/BaseApplicationEngine.kt
    a
    • 2
    • 1
  • g

    gpopides

    09/04/2025, 1:57 PM
    I spent quite some time trying to figure out why bearer authentication did not work and the reason was that the token was an empty string, essentially "Bearer ". Is it specified somewhere that the request will be unauthorized on empty tokens?
    j
    a
    • 3
    • 4
  • a

    Alex Styl

    09/04/2025, 1:58 PM
    How do i start auto reload? Im confused whether I am not running it properly or it's because of this bug that it isn't working for me I am on a kotlin multiplatform project, jvm target:
    ./gradlew demo:jvmRun -Pio.ktor.development=true -t
    a
    a
    • 3
    • 10
  • p

    phldavies

    09/04/2025, 5:42 PM
    In the Ktor Client, is there any reasonable way of handling a
    404
    response as
    null
    without either losing the default response validation (i.e
    expectSuccess = false
    ) or intercepting
    ClientRequestException
    ?
    a
    • 2
    • 4
  • a

    Arjan van Wieringen

    09/05/2025, 12:13 PM
    I was developing some small sideproject in Ktor Server in IntelliJ and I noticed that with ContentNegotiation IntelliJ autocompletes the JSON payloads when creating requests in HTTP files! Amazing! Did not know that was possible, but what a welcome surprise!
    🦜 2
  • a

    Alex Styl

    09/06/2025, 9:49 AM
    I keep finding my server not dying when my gradlew task is dead. I end up having to find which program is using the server port via the terminal and killing it manually, in order to start my server again. Is that a known issue?
    🚫 1
    v
    a
    • 3
    • 4
  • s

    suyash

    09/07/2025, 7:48 PM
    Hello all 👋🏾 Making a post route for adding a Task (name,description are only two fields and required too) 1. handling Validation using RequestValidation Plugin 2. handling Exception through StatusPages
    Copy code
    post {
        val newTask = getTask()
        val id = helper.createTask(newTask)
        call.respond(HttpStatusCode.Created, mapOf("id" to id))
    }
    
    private suspend fun RoutingContext.getTask(): CreateTaskType =
        runCatching { call.receive<CreateTaskType>() }.getOrElse {
            throw BadRequestException("Required fields missing ")
        }
    --------------------------------------------------------------------------
    validate<CreateTaskType> { task ->
                if (task.name.length > 10)
                    ValidationResult.Invalid("XYz")
                else ValidationResult.Valid
            }
    --------------------------------------------------------------------------
    exception<RequestValidationException> { call, cause ->
                call.respond(HttpStatusCode.BadRequest, cause.reasons.joinToString())
            }
    exception<BadRequestException> { call, cause ->
                call.respond(HttpStatusCode.Conflict, cause.message)
            }
    My issue is everytime I make a Faulty API Call I get a BadRequestException => 409 with error Message "Required fields missing" I never get a RequestValidationException => 400 with error Message how can I prevent that and is there a better way to do such things?
    b
    • 2
    • 7
  • c

    Carl-Johan Larsson

    09/08/2025, 12:10 PM
    Hey all, I will shamelessly plug a ktor-related job offer here: https://www.linkedin.com/feed/update/urn:li:activity:7370738424619712512/. Reach out to me if any questions and I will give you more details, hope it's of interest!
    c
    • 2
    • 1
  • r

    Roger Kreienbühl

    09/08/2025, 8:27 PM
    Hi all Ist there a way to easily unit-testing a ktor client plugin, without mocking the whole ktor client? I have a simple plugin that uses only
    onResponse
    b
    a
    a
    • 4
    • 6
  • p

    Philip Segerfast

    09/10/2025, 4:03 PM
    Hi all! At our company we're trying to migrate from Retrofit to Ktor (KMP) but we'd like to modularize the configuration and optimally inject already configured plugins into the HttpClient, like this:
    Copy code
    val client = HttpClient {
        plugins.forEach {
            install(it)
        }
    }
    We started with the Logger. Our idea was to create a custom plugin that installs the Logger and itself and configures it but we found out that you can't do that with Plugins (or can you?). The official documentation asks you to just install Logger explicitly in the HttpClientConfig but we want to do this outside of HttpClient. Is there a common approach on how to do this? Here's one idea I had:
    Copy code
    interface KtorInstallable {
        fun HttpClientConfig<*>.install()
    }
    
    interface PlatformLogger {
        fun logKtor(message: String)
    }
    
    class CustomLoggerPlugin(
        private val platformLogger: PlatformLogger,
    ) : KtorInstallable {
        override fun HttpClientConfig<*>.install() {
            install(Logging) {
                logger = object : Logger {
                    override fun log(message: String) {
                        platformLogger.logKtor(message)
                    }
                }
            }
        }
    }
    
    class CustomHttpClient(plugins: List<KtorInstallable>) {
        val client = HttpClient {
            plugins.forEach { plugin ->
                plugin.run { install() }
            }
        }
    }
    We are quite new to Ktor. Thank you!!
    a
    • 2
    • 3
  • u

    ursus

    09/11/2025, 2:53 AM
    I’m trying to add kmp (ktor) to existing ios app which uses Alamofire. I have trouble with token management, i.e. how to keep the 2 in sync. Is there a way to tell ktor client that tokens were updated, other than getting s 401?
    a
    • 2
    • 8
  • s

    sindrenm

    09/12/2025, 7:51 AM
    Are there any release notes for 3.3.0?
    b
    p
    +4
    • 7
    • 20
  • r

    Rey (Kingg22)

    09/13/2025, 5:50 PM
    Hey everyone, 👋 I’ve been working on a small annotation processor library called Ktorgen, which aims to reduce boilerplate when writing Ktor client APIs. It works in a similar way to Retrofit, with just minor differences in headers and without requiring adapters, converters, or runtime overhead. I just released version 0.4.0, which now includes multi-round KSP support, and it’s already available on Maven Central. If anyone is interested in trying it out and sharing feedback, it would help me a lot to improve it 🙏 👉 GitHub – Ktorgen
    c
    h
    • 3
    • 3
  • m

    Marc

    09/13/2025, 10:27 PM
    Hello! I’m trying to figure out how to et up the openApi generator plugin in a multi module plugin but I’m strugling a lot. Is there any guidelines on how to do it? 🙏🏻
    s
    • 2
    • 5
  • s

    Stefan Oltmann

    09/14/2025, 1:34 PM
    Any idea when zstd support will arrive?
    ✅ 1
    e
    s
    • 3
    • 3
  • a

    Alex Styl

    09/15/2025, 6:28 AM
    how can i serve different directories under the same remote path in ktor server? I have a folder called
    css
    and an other called
    public
    . I want the contents of both to be served at
    /
    a
    • 2
    • 3
  • e

    Emre

    09/18/2025, 4:55 PM
    Why is the ktor openapi plugin running when I run
    gradle kotest
    ? This started happening after I upgraded my dependencies; ktor kotest kotlin etc. I should note that I do use an openapi plugin, but not the ktor one: https://github.com/SMILEY4/ktor-openapi-tools