https://kotlinlang.org logo
Docs
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
ktor
  • d

    dm6801

    11/14/2020, 12:33 PM
    Has anyone had success deploying to Heroku? I got it working by involving shadowJar gradle plugin, would like to know if I could get it to work without this workaround
    j
    • 2
    • 2
  • d

    df

    11/14/2020, 9:10 PM
    hey there. Any chance to disable the json serialization for a single request? I have to deal with an api that is supposed to speak json but expects one serialized json object / line in the body when performing batch operations 😕
    g
    • 2
    • 2
  • c

    cisimon7

    11/14/2020, 9:48 PM
    I wonder what I am doing wrong, but I have been unable to make a simple request from UI (kotlin React) to Ktor backend using the HttpClient. Any pointer to an example please, preferably one done with Ktor version 1.4.0 and above
    d
    • 2
    • 14
  • g

    gbaldeck

    11/14/2020, 11:29 PM
    I have a multiplatform project setup with ktor and I am having issues with running it through intellij. I set some jvm args in the application block of build.gradle.kts to fix errors I was getting, but IntelliJ completely ignores them. I also tried putting them in the gradle run configuration itself and it ignores those too. I've tried rebuilding, remaking the intellij project, invalidating the intellij caches, but nothing works. When I run
    gradlew run
    it sees the jvm args and starts just fine, it's only through intellij that theres a problem. Does anyone know how to fix this issue?
    n
    • 2
    • 5
  • d

    dm6801

    11/15/2020, 1:14 PM
    GraalVM + Ktor here's a good starting point for anyone interested: example utilising "kraal" gradle plugin I would like to get your input, whether it is of interest to ktor developers. Is this a worthwhile endeavour? Is the supposed performance boost, if any, worth the hassle? Does it depend entirely on the use-case?
    n
    • 2
    • 1
  • w

    william

    11/16/2020, 12:17 AM
    i'm using a ktor client with
    JsonFeature
    , but I would like to wrap my return types with a
    Result
    sealed class type of thing instead of exceptions when a network error occurs - any suggestions for going forward with this?
    c
    • 2
    • 2
  • d

    dagomni

    11/16/2020, 12:47 PM
    kotlin.Error: Ktor native HttpClient requires kotlinx.coroutines version with `native-mt` suffix (like `1.3.9-native-mt`). Consider checking the dependencies.
    Has anyone else experienced this? It happens on iOS with Ktor 1.4.1, 1.4.2; coroutines 1.3.9-native-mt, 1.3.9-native-mt-2
    c
    j
    • 3
    • 5
  • a

    arthur_sav

    11/16/2020, 6:10 PM
    What’s your favourite Ktor + Frontend setup? Started with simple HTML/JS + Freemarker but it’s getting messy.
    c
    h
    • 3
    • 9
  • a

    aleksey.tomin

    11/17/2020, 10:40 AM
    I’ve the problem with ktor-curl on macOS.
    val response = <http://httpClient.post|httpClient.post><T>(url) {
                        contentType(ContentType.Application.Json)
                        body = "some json"
                    }
    This code executed on windows ~1 sec but on macOS - first request < 1 sec but next ~ 15 sec. kotlin 1.4.10, ktor 1.4.2,
    io.ktor:ktor-client-curl
    and others. How can I look up a problem?
    e
    j
    • 3
    • 9
  • d

    df

    11/17/2020, 5:08 PM
    is there any way to just write plain text into the body of a post request with the ktor client? I have the following code
    val content = """
                {"identifier":"cdp_9055274"}
                {"identifier":"cdp_9111757"}
                {"identifier":"cdp_9135021"}
            """.trimIndent()
    
            val response = httpClient.patch<String> {
                url("/api/rest/v1/products")
                header("Authorization", "Bearer ${token.accessToken}")
                contentType(ContentType("application", "vnd.akeneo.collection+json"))
                body = content
            }
    and it seems like regardless of what I'm writing into the body (the string, TextContent / ByteArrayContent), the body is always serialized into json again.
    m
    r
    • 3
    • 23
  • a

    Alexander Black

    11/17/2020, 7:02 PM
    Hello all, I’m trying to write a file download method using Ktor on a native/mpp app. here’s my method so far:
    suspend fun HttpClient.downloadFile(
        output: File,
        downloadUrl: Url,
        md5Hash: String
    ): Flow<DownloadResult> {
        return flow {
            try {
                val response = get<HttpResponse> { url(downloadUrl) }
                val data = ByteArray(response.contentLength()?.toInt() ?: 0)
                var offset = 0
                do {
                    val progress = (offset.toDouble() / data.size) * 100
                    emit(DownloadResult.Progress(progress))
                    val currentRead = response.content.readAvailable(data, offset, data.size)
                    offset += currentRead
                } while (currentRead > 0)
    
                if (response.status.isSuccess()) {
                    if (data.md5().hex == md5Hash) {
                        output.write(data)
                        emit(DownloadResult.Success)
                    } else {
                        emit(DownloadResult.ErrorCorruptFile)
                    }
                } else {
                    emit(DownloadResult.ErrorBadResponseCode(response.status.value))
                }
            } catch (e: TimeoutCancellationException) {
                emit(DownloadResult.ErrorRequestTimeout("Connection timed out", e))
            } catch (t: Throwable) {
                emit(DownloadResult.Error("Failed to connect", t))
            }
        }
    }
    The problem is that the 
    response.content.readAvailable()
     method always seems to read the whole file at once without chunking it up, which means my progress emission only gets outputted once. I’m wondering if there’s something I’m doing wrong here? or if that’s normal behaviour? Also as a side note the file I’m testing on is 25MB so it should emit a few times I’d think.
    t
    j
    • 3
    • 4
  • b

    Big Chungus

    11/18/2020, 10:12 AM
    Are there any guides on how to write and use ktor middleware (if it's even possible)
    d
    j
    • 3
    • 3
  • k

    keochris

    11/18/2020, 12:05 PM
    I am building an asynchronous web server using Flask and Celery. The latter is a task queue manager. In the screenshot below, I generate a task ID via a POST request to the web server and the actual task starts 10 seconds later. You can then check the status via an automated task id generated by Celery. I prefer coding with Ktor for obvious reasons but I am struggling to find out a way to do the same thing easily. Does anyone know how to address that? (asynchronous tasks triggered by a post and status easy to assess). I don’t mind adding external components (but not too complex ones 🙂 )
    c
    • 2
    • 4
  • j

    Janez Kolar

    11/19/2020, 8:21 AM
    Hi! I would like to create webserver to send data to frontend via websocket. I found example (below) how to make list of connections and sync data to all. Is there some more efficient way to do this? Something like multicast? Can someone tell me how many clients is possible to connect to such websocket? In real case I need to sync position of 100 cars to 10000 clients every second... What would be the best way with ktor?
    routing {
        val wsConnections = Collections.synchronizedSet(LinkedHashSet<DefaultWebSocketSession>())
    
        webSocket("/chat") { // this: DefaultWebSocketSession
            wsConnections += this
            try {
                while (true) {
                    val frame = incoming.receive()
                    when (frame) {
                        is Frame.Text -> {
                            val text = frame.readText()
                            // Iterate over all the connections
                            for (conn in wsConnections) {
                                conn.outgoing.send(Frame.Text(text))
                            }
                        }
                    }
                }
            } finally {
                wsConnections -= this
            }
        }
    }
    w
    • 2
    • 2
  • s

    Satyam Agarwal

    11/19/2020, 1:04 PM
    I don’t know how I managed to delete my last message. Here it goes, can anyone help me please ? Using ktor (server side) = 1.4.2, coroutines = 1.3.9, jdk14, kotlin = 1.4.10 and proemtheus java client = 0.9.0, this code throws :
    get("/") {
        call.respondTextWriter {
            withContext(IO) {    TextFormat.write004(this@respondTextWriter, CollectorRegistry.defaultRegistry.metricFamilySamples()) } 
        }
    }
    Exception in thread "eventLoopGroupProxy-3-1" kotlinx.coroutines.CoroutinesInternalError: Fatal exception in coroutines machinery for DispatchedContinuation[UnsafeBlockingTrampoline@381151be, Continuation at io.ktor.utils.io.jvm.javaio.OutputAdapter$loop$1.loop(Blocking.kt:311)@33f7436b]. Please read KDoc to 'handleFatalException' method and report this incident to maintainers
    	at kotlinx.coroutines.DispatchedTask.handleFatalException$kotlinx_coroutines_core(DispatchedTask.kt:144)
    	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:115)
    	at io.ktor.utils.io.jvm.javaio.UnsafeBlockingTrampoline.dispatch(Blocking.kt:296)
    	at kotlinx.coroutines.internal.DispatchedContinuation.resumeWith(DispatchedContinuation.kt:184)
    	at io.ktor.utils.io.jvm.javaio.BlockingAdapter$end$1.resumeWith(Blocking.kt:163)
    	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
    	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
    	at io.ktor.utils.io.jvm.javaio.UnsafeBlockingTrampoline.dispatch(Blocking.kt:296)
    	at kotlinx.coroutines.internal.DispatchedContinuation.resumeWith(DispatchedContinuation.kt:184)
    	at io.ktor.utils.io.internal.CancellableReusableContinuation.resumeWith(CancellableReusableContinuation.kt:93)
    	at io.ktor.utils.io.ByteBufferChannel.resumeWriteOp(ByteBufferChannel.kt:2258)
    	at io.ktor.utils.io.ByteBufferChannel.bytesRead(ByteBufferChannel.kt:929)
    	at io.ktor.utils.io.ByteBufferChannel.consumed(ByteBufferChannel.kt:1953)
    	at io.ktor.server.netty.cio.NettyResponsePipeline$processBodyFlusher$2.invokeSuspend(NettyResponsePipeline.kt:305)
    	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
    	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
    	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472)
    	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)
    	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
    	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
    	at io.ktor.server.netty.EventLoopGroupProxy$Companion$create$factory$1$1.run(NettyApplicationEngine.kt:215)
    	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
    	at java.base/java.lang.Thread.run(Thread.java:832)
    Caused by: java.lang.ClassCastException: class kotlin.coroutines.jvm.internal.CompletedContinuation cannot be cast to class kotlinx.coroutines.internal.DispatchedContinuation (kotlin.coroutines.jvm.internal.CompletedContinuation and kotlinx.coroutines.internal.DispatchedContinuation are in unnamed module of loader 'app')
    	at kotlinx.coroutines.CoroutineDispatcher.releaseInterceptedContinuation(CoroutineDispatcher.kt:104)
    	at kotlin.coroutines.jvm.internal.ContinuationImpl.releaseIntercepted(ContinuationImpl.kt:118)
    	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:39)
    	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
    	... 22 more
    `
    👍 2
    e
    t
    e
    • 4
    • 5
  • r

    Robert Jaros

    11/19/2020, 3:07 PM
    As
    kotlinx-coroutines-1.4.1-native-mt
    has just been released, when can we expect new Ktor release, with coroutines 1.4 and the fix for KTOR-1286?
    c
    j
    • 3
    • 6
  • o

    okaymak

    11/19/2020, 7:30 PM
    I am using ktor client in a mpp project and I am trying to post form-data:
    client.submitFormWithBinaryData {
        url { encodedPath = "my_url" }
        formData {
            append("my_key", "my_key_value")
        }
    }
    Bu then get an error from kotlinx serialization:
    kotlinx.serialization.SerializationException: Serializer for class 'MultiPartFormDataContent' is not found.
    What am I missing here?
    c
    r
    a
    • 4
    • 8
  • d

    Davide Giuseppe Farella

    11/20/2020, 4:06 PM
    [Client] Hello everyone, I’m configuring my client with a
    defaultRequest { }
    and I want a parameter to be used only for some path, what’s the best way? Details in thread
    • 1
    • 2
  • j

    Joost Klitsie

    11/22/2020, 9:38 AM
    Hi everyone, is it possible to override features? For example: I have a feature that allows actions from a user (GET/PUT/Whatever) based on a role, but also based on an exception in this rule. I want all my routes to default that you would need to be logged in as ADMIN, except if I override it (which could be route specific) For example:
    routing {
        withRole(ADMIN) {
             route("admin_only_route") {
             }
    
             withRole(USER) {
                 route("special_route") {
                 }
             }
               
        }
    }
    j
    • 2
    • 14
  • a

    Azur Haljeta

    11/23/2020, 9:30 AM
    Is there any websocket ktor client example, in which the entry object is available so it can be used to cancel or start the websocket session. So far, there is that example where you manage the websocket session within a scoped block of code and it isn't available to the outside world.
    j
    e
    b
    • 4
    • 6
  • a

    aleksey.tomin

    11/24/2020, 2:55 AM
    I’ve found some strange problem with the latest kotlin+coroutinues+ktor and macOS CURL request slowly - 2-3 seconds instead if 400-500ms. The fix is weird - remove
    app.run()
    https://github.com/alekseytomin/coroutines-problem/pull/1 It’s a ktor’s bug? Or coroutinue’s bug?
    • 1
    • 1
  • m

    manlan

    11/24/2020, 5:41 PM
    How do I access properties from
    application.conf
    from a non-Ktor object class?
    j
    a
    • 3
    • 5
  • n

    Nish Patel

    11/25/2020, 6:21 AM
    Hi guys, how would we use mockengine for mocking the response from an endpoint, if some one could give an example or some kind of explanation would be good
    c
    • 2
    • 1
  • m

    mmaillot

    11/25/2020, 9:35 PM
    Hi! How can I send a 204 No content response without content ?
    call.respond(HttpStatusCode.NoContent, Unit)
    I have
    {}
    in the content.
    c
    m
    m
    • 4
    • 5
  • c

    Cicero

    11/26/2020, 12:50 AM
    Is it standard for Ktor or KotlinxSerialization to chop a request? I was trying to understand what was happening and after inspecting into the
    @Deprecated("This is going to become internal. Use Pipeline.execute() instead.")
    public fun <TSubject : Any, TContext : Any> pipelineExecutorFor(
        context: TContext,
        interceptors: List<PipelineInterceptor<TSubject, TContext>>,
        subject: TSubject
    ): @Suppress("DEPRECATION") PipelineExecutor<TSubject> {
        return SuspendFunctionGun(subject, context, interceptors)
    }
    I found that my body is being sent in half
    • 1
    • 4
  • b

    bitkid

    11/26/2020, 12:18 PM
    Hi! please help! 🙂 We are a few days from our release and stupid me upgraded to kotlin 1.4.20 and ktor 1.4.2 .. very simple handler:
    get("/test") {
                call.respondTextWriter(contentType = ContentType.Text.CSV) {
                    repeat(100000) {
                        write("bla")
                    }
                }
            }
    result:
    Exception in thread "eventLoopGroupProxy-3-2" kotlinx.coroutines.CoroutinesInternalError: Fatal exception in coroutines machinery for DispatchedContinuation[UnsafeBlockingTrampoline@28448af8, Continuation at io.ktor.utils.io.jvm.javaio.OutputAdapter$loop$1.loop(Blocking.kt:311)@4245d158]. Please read KDoc to 'handleFatalException' method and report this incident to maintainers
    	at kotlinx.coroutines.DispatchedTask.handleFatalException$kotlinx_coroutines_core(DispatchedTask.kt:93)
    	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:64)
    	at io.ktor.utils.io.jvm.javaio.UnsafeBlockingTrampoline.dispatch(Blocking.kt:296)
    	at kotlinx.coroutines.DispatchedContinuation.resumeWith(DispatchedContinuation.kt:184)
    	at io.ktor.utils.io.jvm.javaio.BlockingAdapter$end$1.resumeWith(Blocking.kt:163)
    	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
    	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
    	at io.ktor.utils.io.jvm.javaio.UnsafeBlockingTrampoline.dispatch(Blocking.kt:296)
    	at kotlinx.coroutines.DispatchedContinuation.resumeWith(DispatchedContinuation.kt:184)
    	at io.ktor.utils.io.internal.CancellableReusableContinuation.resumeWith(CancellableReusableContinuation.kt:93)
    	at io.ktor.utils.io.ByteBufferChannel.resumeWriteOp(ByteBufferChannel.kt:2258)
    	at io.ktor.utils.io.ByteBufferChannel.bytesRead(ByteBufferChannel.kt:929)
    	at io.ktor.utils.io.ByteBufferChannel.consumed(ByteBufferChannel.kt:1953)
    	at io.ktor.server.netty.cio.NettyResponsePipeline$processBodyFlusher$2.invokeSuspend(NettyResponsePipeline.kt:305)
    	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
    	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
    	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472)
    	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)
    	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
    	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
    	at io.ktor.server.netty.EventLoopGroupProxy$Companion$create$factory$1$1.run(NettyApplicationEngine.kt:215)
    	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
    	at java.base/java.lang.Thread.run(Thread.java:832)
    Caused by: java.lang.ClassCastException: class kotlin.coroutines.jvm.internal.CompletedContinuation cannot be cast to class kotlinx.coroutines.DispatchedContinuation (kotlin.coroutines.jvm.internal.CompletedContinuation and kotlinx.coroutines.DispatchedContinuation are in unnamed module of loader 'app')
    	at kotlinx.coroutines.CoroutineDispatcher.releaseInterceptedContinuation(CoroutineDispatcher.kt:103)
    	at kotlin.coroutines.jvm.internal.ContinuationImpl.releaseIntercepted(ContinuationImpl.kt:118)
    	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:39)
    	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:55)
    	... 22 more
    s
    c
    • 3
    • 11
  • b

    bitkid

    11/26/2020, 2:43 PM
    can i run ktor 1.4.1 with kotlin 1.4.20 and serialization 1.4.20?
    :yes: 4
    c
    • 2
    • 2
  • r

    Robert Wijas

    11/26/2020, 5:38 PM
    Hey 👋 I’m using ktor client with Json feature installed. Some of my requests are downloading json files via
    ByteReadChannel
    (I just need to save them in local file storage) but looks like ktor is running those through json parsing as well (probably because content type is
    application/json
    ). This results in an exception, because there’s not enough information to deserialize response data. Any hints? Or should I just file a github issue? Thanks!
    • 1
    • 1
  • m

    Marcin Wisniowski

    11/26/2020, 11:16 PM
    Hello, I am using a Ktor client with the Json feature to receive some Json objects, but I also need to access the response headers. I can see them if I get the HttpResponse object, but then I don't have my deserialized Json object. How do I retrieve both the Json object and the response headers?
    j
    j
    • 3
    • 3
  • j

    Jérôme Gully

    11/27/2020, 2:47 PM
    Hi, I use the Ktor http client in a MP project, I have an api url with a custom part like
    "users/{name}/commits"
    , is there something in Ktor to handle this ? For the moment I use `"users/{name}/commits".replace("{name}", "Jérôme")`🙃 Retrofit handle it like this :
    @GET("users/{name}/commits")
    Call<List<Commit>> getCommitsByName(@Path("name") String name);
    m
    • 2
    • 3
Powered by Linen
Title
j

Jérôme Gully

11/27/2020, 2:47 PM
Hi, I use the Ktor http client in a MP project, I have an api url with a custom part like
"users/{name}/commits"
, is there something in Ktor to handle this ? For the moment I use `"users/{name}/commits".replace("{name}", "Jérôme")`🙃 Retrofit handle it like this :
@GET("users/{name}/commits")
Call<List<Commit>> getCommitsByName(@Path("name") String name);
m

mmaillot

11/27/2020, 2:51 PM
You can use string template : “users/$name/commits” where $name is the variable containing Jérôme.
j

Jérôme Gully

11/27/2020, 4:45 PM
Thanks, yep it's nice but it's working only if you have the path IN the method, you can't refer to an extern property to reuse it
m

mmaillot

11/27/2020, 5:03 PM
It’s the same for Retrofit. But I see what you want but I don’t have solution. Perhaps an other lib...
View count: 6