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
  • k

    Ky

    06/20/2022, 6:59 PM
    Does Ktor’s
    HttpClient
    kick off it’s own coroutine to make requests? And do we have any control over that coroutineContext? I’m having trouble getting ktors HttpClient to behave nicely in regards to synchronization. Unless I wrap the
    .get()
    in
    withContext(runTest.coroutineContext)
    my tests do not wait for ktor request to return and the test will complete prematurely
    a
    p
    • 3
    • 6
  • c

    Chico

    06/20/2022, 7:30 PM
    Hello folks, does anyone have been use hibernate + hikari and ktor in production? I’ve using those lib because I’m using google spanner has database and I’m facing some problem with opened connections and I might think that is my hikari configurations with some missing properties but I really dont know. May someone already used ktor + hibernate + hikaricp?
  • x

    xxfast

    06/21/2022, 2:32 AM
    in ktor-client, is there a way to add headers in a suspended context?
    a
    h
    • 3
    • 5
  • h

    Helio

    06/21/2022, 11:31 AM
    Hello again, 👋🏽 I was doing a bit of research regarding the best approach to Gracefully Shutdown a Ktor server (Netty Engine - more specifically). Looking through the documentation, I thought that the recommended way would be through Application Monitoring Events (e.g getting SIGTERM signals). However, during my tests, I noticed that
    onStopping, onPrepareStop and onStopped
    ApplicationEvents are not triggered for Netty Engine? Is that expected? If so, do you have any suggestion to properly handle those Graceful Shutdowns? Thanks once again for your help.
    a
    a
    • 3
    • 7
  • c

    cafonsomota

    06/21/2022, 11:41 AM
    hello all! I’ve just updated Ktor 2.0.0-beta-1 to 2.0.2 (client), and I’ve noticed something strange happening: • When a request fails (for instance, receiving a 403), I get the deserialized object as null instead of an exception For example:
    public suspend fun someCall(random: RandomObject): SomeObject = <http://client.post|client.post>(URL) {
      setBody(random)
    }.body()
    Previously, when I called this from:
    public suspend fun invokeSomeCall(random: RandomObject, onSuccess: (SomeObject) -> Unit, onFailure: (SomeErrorObject) -> Unit) {
      try {
        val response = EntityManagerAPI.someCall(random)
    
        coroutineScope {
          onSuccess(response)
        }
      } catch (e: Exception) {
        coroutineScope {
          onFailure(processException(e))
        }
      }
    }
    And the server returns a 403, the deserialization of
    SomeObject
    would fail, and I’ll call
    onFailure
    . Now, with the new version,
    onSuccess
    is called and it’s deserialized with all the default values. The rules that I’m using for
    Json
    on
    ContentNegotation
    are:
    public val nonStrictJson: Json = Json {
      prettyPrint = true
      isLenient = true
      ignoreUnknownKeys = true
    }
    From my tests if I change
    isLenient
    to false, I get the previous behaviour; in any case I’m trying to understand what changed, or what I might be doing wrong? Is there a better approach here? Perhaps, checking the status code before?
    h
    • 2
    • 7
  • d

    David Smith

    06/22/2022, 11:00 AM
    Has anyone come across ktor server using CIO hanging on requests? I can’t pin it down yet but I have multiple requests hitting my server at once and it seems one of them at least is hanging, once it times out on the client side the other requests are handled fine. If I change to use the Netty engine then everything is fine
    a
    • 2
    • 6
  • s

    Sean Proctor

    06/22/2022, 12:22 PM
    I'm attempting to switch some code from okhttp to ktor-client. the server (IP camera) uses digest authentication. My implementation with okhttp uses https://github.com/rburgst/okhttp-digest and works fine. Trying to use ktor, I'm getting authentication errors. The biggest difference that I see is that okhttp-digest has "algorithm=MD5" in the Authorization header, while ktor doesn't. Is there a simple way to add that so I can test if that's the issue or if it's something else?
    • 1
    • 4
  • s

    subham

    06/22/2022, 1:33 PM
    I am facing the below problem after updating to ktor 2.0.2 and enabling a new memory model in kmp library project.
    e: Could not find "io.ktor:ktor-http-cio" in [/Users/subhamtyagi/Library/Application Support/kotlin/daemon]
    e: java.lang.IllegalStateException: FATAL ERROR: Could not find "io.ktor:ktor-http-cio" in [/Users/subhamtyagi/Library/Application Support/kotlin/daemon]
    Kotlin - 1.6.21 ktor-2.0.2 coroutine-1.6.3 More logs are in the thread
    a
    • 2
    • 2
  • t

    Trey

    06/22/2022, 8:19 PM
    Can somebody explain how to configure SSL with Darwin HttpClient? I'm getting this exception when I try to connect to a web socket over SSL. io.ktor.client.engine.darwin.DarwinHttpRequestException: Exception in http request: Error Domain=NSURLErrorDomain Code=-1011 "There was a bad response from the server."
    l
    a
    • 3
    • 10
  • a

    Austin Pederson

    06/22/2022, 9:46 PM
    I am running up against an issue using Ktor 2.0.2 with SSL. I am trying to create a multiplatform application for iOS and Android but my API requests are causing a crash on Android (haven't checked iOS yet). This is being caused by an SSL issue. I followed the guide for setting up SSL on Android for the engine I am using, but my keystore is not being found. Are there any guides or examples out there for how to do SSL in KMM?
    a
    • 2
    • 2
  • c

    Cheick Kante

    06/23/2022, 6:38 PM
    I just migrated to Ktor 2.0.2 folling IntellijIdea migration tool.. Surprisingly, all compiles fine however I keep getting this error too
    a
    • 2
    • 1
  • r

    Raphael TEYSSANDIER

    06/24/2022, 3:34 PM
    Hello, I’m building a server, REST API, with ktor, and I was wondering what’s the best framework to build a admin panel with it ? And it is even possible ?
    a
    • 2
    • 2
  • h

    Hamza GATTAL

    06/25/2022, 10:40 PM
    Hi everyone Ktor support graphql?
    g
    e
    • 3
    • 2
  • l

    Lawrence

    06/27/2022, 4:36 AM
    Can anyone help me with this please?
    a
    d
    r
    • 4
    • 5
  • b

    Bao Le Duc

    06/27/2022, 6:09 AM
    Hi, I’m using Ktor Web Socket in a multiplatform project (Android/iOS). I saw auto-retry for http request, but no option for websocket connection. Does it work with Ktor Web Socket or any other option? My use-case is that the app keeps a Web Socket connection to the server. From time to time, the connection is dropped due to client connectivity (ex. switch between wifi/data, connection glitch) or backend (ex. scaling optimization). I would like to implement an auto reconnect logic when it’s dropped.
  • i

    itzik kasovitch

    06/27/2022, 8:46 AM
    Hi, In my application that is running on top of Ktor 1.6.4 I noticed that call.receiveText() returns a garbled string if the input text is in Japanese. I ruled out that it happens on the client side. Is there some configuration I forgot to do to make receiveText handle Japanese correctly?
    a
    • 2
    • 10
  • a

    Aleksei Tirman [JB]

    06/27/2022, 11:42 AM
    Quick poll. Should a server under test be configured with
    application.conf
    from the
    main
    sourceset if the config in the
    test
    sourceset is absent?
    :yes:
    🇳🇴
    :yes: 9
    🇳🇴 3
    a
    • 2
    • 5
  • j

    John O'Reilly

    06/27/2022, 1:07 PM
    Is there a way when using Ktor embedded server with Netty to block use of TLS 1.0 and 1.1?
    a
    e
    • 3
    • 29
  • r

    Rodrigo Silva

    06/27/2022, 8:53 PM
    Hello everybody. Is there something already "ready" to add roles to routes that need authentication? Like :
    authenticate {
    ("need_admin_role or user_role")
    post("/some_route) { @TODO }
    }
    e
    • 2
    • 1
  • b

    brabo-hi

    06/28/2022, 12:02 AM
    Hi all, when using ktor, how can i redirect to another page and passing data? I have 2 pages (login and detail) and freemarker as template engine. On login page after form is submit, i would like to redirect to page detail
    call.respondRedirect()
    instead of rendering the new page
    call.respondTemplate('detail.ftl', mapOf("myData" to myValue))
    however i need to send some data to the new page when rendering the template
    a
    • 2
    • 5
  • s

    Slackbot

    06/28/2022, 7:43 AM
    This message was deleted.
    a
    r
    • 3
    • 4
  • r

    ram prasad

    06/28/2022, 7:50 AM
    Hello Team, Newbie to Kotlin and Ktor. I need help in adding unit tests which uses a testing database. Is there a reference that I can follow. I'm using Ktor
    2.0.2
    . Basically I need to understand the setup(connection to test db and create data for testing) and teardown(cleanup of test data after all tests) parts using the
    testApplication
    Thanks in advance!
    a
    • 2
    • 5
  • r

    ram prasad

    06/28/2022, 7:50 AM
    @channel
    👎 1
    👎🏾 1
  • a

    André Martins

    06/28/2022, 8:23 AM
    Hello, I’m trying have interoperability with java and Im using the ktor client and which to receive the body of a response but since
    receive
    method is an inline reified I cannot call it from java? Is there any other solution?
    s
    • 2
    • 9
  • m

    Martin Gaens

    06/28/2022, 12:45 PM
    I'm making a library that uses Ktor Client in the background, but for some reason when I use it (when I use the
    .jar
    ), I get a
    NoClassDefFoundError
    . This is the full stack trace:
    Exception in thread "main" java.lang.NoClassDefFoundError: io/ktor/client/engine/cio/CIO
    	at com.gitlab.djsushi123.kotlintelegrambotmother.Bot.<init>(bot.kt:22)
    	at com.gitlab.djsushi123.kotlintelegrambotmother.BotKt.buildBot(bot.kt:57)
    	at MainKt.main(Main.kt:7)
    	at MainKt$main$2.invoke(Main.kt)
    	at MainKt$main$2.invoke(Main.kt)
    	at kotlin.coroutines.intrinsics.IntrinsicsKt__IntrinsicsJvmKt$createCoroutineUnintercepted$$inlined$createCoroutineFromSuspendFunction$IntrinsicsKt__IntrinsicsJvmKt$1.invokeSuspend(IntrinsicsJvm.kt:205)
    	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    	at kotlin.coroutines.ContinuationKt.startCoroutine(Continuation.kt:115)
    	at kotlin.coroutines.jvm.internal.RunSuspendKt.runSuspend(RunSuspend.kt:19)
    	at MainKt.main(Main.kt)
    Caused by: java.lang.ClassNotFoundException: io.ktor.client.engine.cio.CIO
    	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
    	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
    	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
    	... 10 more
    What am I doing wrong? The library uses Gradle. This is my `build.gradle.kts`:
    plugins {
        id("org.jetbrains.kotlin.jvm") version "1.7.0"
        kotlin("plugin.serialization") version "1.7.0"
    
        `java-library`
    }
    
    version = "0.0.1-alpha"
    
    repositories {
        // Use Maven Central for resolving dependencies.
        mavenCentral()
    }
    
    dependencies {
        implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
    
        implementation("org.jetbrains.kotlin:kotlin-stdlib")
    
        api("io.ktor:ktor-client-core:2.0.2")
        api("io.ktor:ktor-client-cio:2.0.2")
    
        api("io.ktor:ktor-client-content-negotiation:2.0.2")
        api("io.ktor:ktor-serialization-kotlinx-json:2.0.2")
    
        api("io.ktor:ktor-client-resources:2.0.2")
    
        // Use the Kotlin test library.
        testImplementation("org.jetbrains.kotlin:kotlin-test")
    
        // Use the Kotlin JUnit integration.
        testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
    }
    a
    • 2
    • 8
  • f

    fbodr

    06/28/2022, 12:47 PM
    Hi all, good day. I would like to hear about you experience with DI in ktor apps. I see that ktor has a example with Kodein , which I looked into. Also, I know some people do use Koin. I can’t find a good comparison between both. Koin API seems more ‘kotlin’ to me then kodein, but I would like to hear about the experiences… Most info on internet is more about Android then Ktor …
    c
    • 2
    • 6
  • s

    Sebastien Leclerc Lavallee

    06/28/2022, 9:05 PM
    Hi all! I have develop a ktor app locally and I have routes likes
    /account
    or
    /events
    that I would call at
    <http://localhost:8080/events>
    for example. Now I have deployed it on a server at something like
    <https://some.domain/api/>
    and I call endpoints at
    <https://some.domain/api/events>
    . Now there aren’t any route that is matched when I call that endpoint. I have an intercept where I print the request path and it says the path is
    /api/events
    which makes sense. My question is, how do I tell ktor that it’s hosted under a specific path ? In this case
    /api
    . This way, it would strip the
    /api
    part and the route would get matched and my code would run as expected. Thanks 🙂
    a
    • 2
    • 8
  • f

    fbodr

    06/29/2022, 8:27 AM
    Hi all. I just found out that, depending on the combination of plugins we select on intellij ktor project creator, or start.ktor.io , we can generate a ‘broken’ app if we select to configured the application with a config file instead of code. The app is broken in the sense that it will generate a sample test that fails because of the module initialisation . Could someone tell me where can I report that ? actually, the whole interaction between testApplication{} builder and configuration files seems kind of weird to me.. I had plenty of problems with that …
    a
    • 2
    • 1
  • p

    Paul Woitaschek

    06/29/2022, 11:41 AM
    @Aleksei Tirman [JB] https://repo.maven.apache.org/maven2/io/ktor/ktor-client-core-watchosarm64/2.0.3/ktor-client-core-watchosarm64-2.0.3.pom is missing, all other variants seem to have built successful yesterday at approx 4pm
    a
    • 2
    • 1
  • s

    spierce7

    06/29/2022, 3:44 PM
    Can anyone speak to their migration experience moving to 2.0? I’ve been waiting for a few releases before I move production servers over. Is anyone running 2.0 in prod?
    s
    r
    • 3
    • 7
Powered by Linen
Title
s

spierce7

06/29/2022, 3:44 PM
Can anyone speak to their migration experience moving to 2.0? I’ve been waiting for a few releases before I move production servers over. Is anyone running 2.0 in prod?
s

Satyam Agarwal

06/30/2022, 2:49 AM
Migrate to 2.0.3 directly. Lots of issues with content-type headers and manipulating request bodies.
Use ktor migration plugin, made my life a lot easier. So many namespaces changes. And even after plug-in migrated namespaces, I had to do a lot of cleanup myself.
I had to replace lots of deprecated apis myself. You don't need to do it, but eventually you'd have to, and replacing withTestApplication with testApplication is a major pain.
s

spierce7

06/30/2022, 2:52 AM
There isn’t a rush for me to migrate. I’m just trying to move over once everything is stable
s

Satyam Agarwal

06/30/2022, 3:17 AM
Sure. But overall I am pretty happy with the new version. And two of my very critical applications are running on 2.0.3 in production without any problems.
s

spierce7

06/30/2022, 3:33 AM
thank you
r

ribesg

06/30/2022, 8:35 AM
I’m waiting on 2.1.0 because I need this to replace a custom Ktor 1.0 feature that I don’t want to reimplement as a Ktor 2.0 plugin https://github.com/ktorio/ktor/commit/7820574232b755c50a71e1249f0c84cd91e17630
View count: 4