https://kotlinlang.org logo
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
  • v

    Vivek Modi

    03/01/2022, 3:51 PM
    Hey everyone, I am new in ktor. I am trying to use KMM in my android and ios project. In my project there is bunch of api call through retrofit with okhttp3. I don't want to change previous retrofit. Now I want to use ktor for new feature api call only so I can share business logic with ios project. I wonder can I use okHttp3 or I can use only ktor http client?
    a
    • 2
    • 2
  • n

    Nathan Kleinschmidt

    03/01/2022, 9:50 PM
    What is the recommended configuration for using GraphQl with Ktor 2.0? Some libraries like KGraphQl only support Ktor 1.x. Are there any plans by the Ktor team to offer a GraphQl plugin?
    d
    a
    e
    • 4
    • 11
  • с

    Стефан Јовановић

    03/02/2022, 11:44 AM
    I've received this error:
    java.lang.NoSuchMethodError: java.nio.ByteBuffer.position(I)Ljava/nio/ByteBuffer;
    After trying to make a request to this endpoint:
    post("/home") {
        call.sessions.set(UserSession(id = "123", name = "Name"))
        call.respondRedirect(Endpoint.Authorized.path)
    }
    I'm using 2.0.0-beta-1 version.
    e
    h
    j
    • 4
    • 20
  • b

    Brais Gabin

    03/02/2022, 4:47 PM
    I'm using ktor cli. Is there a way to create a fake of
    HttpResponse
    ? I would like to use it to test a function that receives an
    HttpResponse
    and returns a
    Result
    . I know that I could use
    MockEngine
    to create a
    HttpResponse
    but it feels too much. I'm assuming that
    HttpResponse
    is something similar as
    Response
    in
    Retrofit
    . And there I could use
    Response.error()
    or
    Response.success()
    to create fakes.
    a
    j
    e
    • 4
    • 15
  • d

    dany giguere

    03/02/2022, 10:29 PM
    Anyone would be willing to mentor me on learning Ktor 1(server) with Exposed ? I’m willing to pay. Please send PM. I’ve accomplished a lot so far by myself but I can’t figure out how to set a oneToMany relationship with exposed, I’d need help with Koin and I’d like to get code reviews/tips. You can view my learning project here : https://bitbucket.org/danygiguere/ktor_1_demo/src/master/
    b
    • 2
    • 1
  • h

    Hayden Meloche

    03/03/2022, 2:35 AM
    I have a ktor plugin that supports version 1.6. I'm looking to update it to support ktor v2. Is their any migration guide for this? I've seen the API changes but im most interested in what it takes to make my plugin native compatible. I believe I need a .api file like this but not sure how I can generate this. Any pointers or examples would be appreciated 😄
    d
    • 2
    • 1
  • j

    J Man

    03/03/2022, 6:48 AM
    If I'm starting a new project in Ktor for learning purposes should I use Ktor-2.0?
    c
    a
    +2
    • 5
    • 6
  • j

    Joakim Forslund

    03/03/2022, 8:45 AM
    Any chance for https://github.com/ktorio/ktor/tree/main/ktor-server/ktor-server-plugins/ktor-server-html-builder to support native with the ktor 2.0.0 release?
    a
    e
    • 3
    • 6
  • t

    Tomas Kormanak

    03/03/2022, 10:40 AM
    I am looking for simple token based authentication in Ktor server. Is there a provider for it? Basically I need to get the token from Authorization header and process it in validate function.
    a
    k
    • 3
    • 3
  • a

    ade

    03/03/2022, 12:12 PM
    I can't find this in the docs or google... say i have a api with url https://exampleapi.com/{param1}/info How do I create a request so that I insert the param1 parameter in a safe url-encoded way? Do I need to encode it manually?
    a
    • 2
    • 2
  • h

    humblehacker

    03/03/2022, 7:27 PM
    Does Ktor client for iOS support background uploads/downloads, and if not, is this planned?
    a
    • 2
    • 2
  • d

    dany giguere

    03/03/2022, 10:04 PM
    Am I wrong or https://github.com/aymanizz/ktor-i18n isn’t supporter on Ktor 1 anymore ? When I try installing the dependency, I get this error :
    app.demo:test: Could not find com.github.aymanizz:ktor-i18n:1.0.0.
    a
    w
    • 3
    • 3
  • b

    benkuly

    03/04/2022, 3:09 PM
    Are there plans to make shared ktor server stuff multiplatform? I use
    testApplication
    to test ktor client stuff, because I really don't like the ktor client mock api and with
    testApplication
    I can re-use type safe routes (
    @Resource
    ). The problem is, that
    testApplication
    is only available for jvm and native and so I cant't test the client code on other platforms.
    ➕ 2
    a
    e
    • 3
    • 9
  • b

    Barry Fawthrop

    03/04/2022, 7:11 PM
    Hi all, How can one pass a data class as a parameter so that ktor-client can return that class type? I can force val result: MyClass = apiclient.post(…) but I want MyClass to be flexible, thanks
    a
    • 2
    • 5
  • e

    Enrico Saggiorato

    03/05/2022, 10:52 AM
    Hey, I'm having some trouble with kotlinx.serialization, I defined a class to deserialize a request, annotated it with Serializable and then from inside a route I'm calling call.receiveOrNull<MyRequest>() But insted of null I'm getting an exception when the request is bad formed. Is this the expected behavior? And if yes what's the point of receiveOrNull?
    a
    b
    • 3
    • 4
  • b

    Barry Fawthrop

    03/06/2022, 6:59 PM
    What are the differences between HttpClient(CIO) and HttpClient(OkHttp) with regards to ktor-client not server? Thanks
    c
    a
    • 3
    • 4
  • a

    arnaud.giuliani

    03/07/2022, 5:33 PM
    Hi Ktor Team 👋 I’m the lead of #koin project. I’m wondering if you will continue to publish new 1.x versions? Just to know if next version of Koin will go with Ktor 2 or if we need to serve both 1.x & 2.x versions
    a
    e
    • 3
    • 5
  • m

    martmists

    03/08/2022, 5:50 PM
    How do I respond with an image when the ContentNegotiation feature is installed?
    a
    • 2
    • 3
  • j

    jmfayard

    03/09/2022, 10:14 AM
    I'm upgrading
    Ktor 2
    from an EAP version to
    2.0.0-beta-1
    The EAP version was available at https://maven.pkg.jetbrains.space/public/p/ktor/eap/io/ktor/ but that doesn't seem to be the case of the beta version nor is it published on mavenCentral() Am I missing something?
    a
    • 2
    • 1
  • a

    ade

    03/09/2022, 3:26 PM
    are there any plans to use KSP for the resources plugin in 2.x? To e.g. get compile time safety for parameters, maybe be able to omit parent
    a
    r
    • 3
    • 2
  • a

    adjpd

    03/09/2022, 6:30 PM
    Hi, I changed from ktor-client
    1.6.7
    to
    2.0.0
    because
    1.6.7
    doesn't work on
    iosArm64
    . Now I get this error:
    Could not find org.jetbrains.kotlin:kotlin-stdlib-common:1.6.20-M1-106 Required by: project: shared.
    Any ideas?
    a
    • 2
    • 3
  • b

    Bridgette Powell

    03/09/2022, 11:18 PM
    Hey there, this is probably a newbie question, but since it’s related to ktor: To get this code below working…why do I have to import both
    io.ktor.server.application.call
    and
    io.ktor.server.response.respondText
    ? What is it about the
    call
    property that requires both imports? I would have thought just importing
    io.ktor.server.application.call
    is enough. Then calling
    call.respondText()
    is ok, but I get an Unresolved Reference error if I dont include the other import.
    package com.mobilecoin.plugins
    
    import io.ktor.server.application.Application
    import io.ktor.server.application.call
    import io.ktor.server.response.respondText
    import io.ktor.server.routing.get
    import io.ktor.server.routing.routing
    
    fun Application.configureRouting() {
    
        // Starting point for a Ktor app:
        routing {
            get("/") {
                call.respondText("Hello World!")
            }
        }
        routing {
        }
    }
    Thanks!
    b
    a
    • 3
    • 3
  • w

    Werner Guttmann

    03/10/2022, 1:43 PM
    Hi; any idea why the IntelliJ services tools window fails to show any ktor projects (built with 2.0.0-beta, if that makes a difference) ?
    a
    • 2
    • 3
  • a

    ansman

    03/10/2022, 4:02 PM
    This is interesting. One of my ktor tests is hanging indefinitely. If I pause in the debugger I can see that it’s hung trying to write some bytes to the output stream. This just started happening and I’m unsure why. At first I thought it was because nobody was consuming the response body but that isn’t the case I think. The test uses the test application which I believe reads the entire body. This is the test in question:
    withTestApplication({ module(config) }) {
        assertEquals(
            HttpStatusCode.Unauthorized,
            handleWebSocket("/some/path") {
                addHeader(HttpHeaders.Authorization, "Bearer invalid")
            }.response.status()
        )
    }
    a
    • 2
    • 3
  • j

    jozefdransfield

    03/10/2022, 11:03 PM
    Hi all, i am trying to stream redis pub sub messages to a websocket connection with this code
    webSocket("/receive/{channel}") {
        val messageFlow: Flow<String> = callbackFlow {
        val jedis = jedisPool.resource
    
        jedis.subscribe(object : JedisPubSub() {
            override fun onMessage(channel: String, message: String) {
                trySendBlocking(message)
            }
        }, channel)
    
        awaitClose {
            jedis.close()
        }
    }
    
    
    messageFlow.cancellable().collect { message ->
        send(message)
    }
     print("Websocket closed")
    }
    The issue is when the client closes the socket i never see the Websocket closed message, I presume the messageFlow isnt being cancelled? Is there a solution to this?
    • 1
    • 1
  • l

    Lucas León

    03/11/2022, 3:05 AM
    Hi everyone, already reported this error in YouTrack but wanted to know if someone faced a similar issue and how they solved it: https://youtrack.jetbrains.com/issue/KTOR-4002
    a
    • 2
    • 3
  • a

    Andrew Reed

    03/11/2022, 11:42 AM
    Hi all, im using ktor 2.0.0-eap-317 (the only version that seems to work properly with HttpCache for ios and android). I have some unit tests from previous version of ktor 1.6.6, where i check for request exceptions around 404, 308, etc. But those tests now fail
    but was io.ktor.client.call.NoTransformationFoundException: No transformation found: class io.ktor.utils.io.ByteBufferChannel -> class com.a.mp.networking.TestData
    So sending a request asking for a json object response but then i tell my test engine client to respond with a 404 error, but instead it seems to be trying to serialise the 404 error.
    s
    • 2
    • 7
  • w

    Wietlol

    03/12/2022, 11:14 AM
    Hi I am trying to fix some performance issues with Ktor's HttpClient with curl engine for Kotlin/Native but I am not sure how to proceed from here I noticed that the http calls to localhost take above 100ms, even though the server can respond in 2ms or less Reproducing the issue locally and running it a few times (even though I am using very primitive tools to measure the performance) shows that it does indeed run very slow https://paste.ofcode.org/GYkS6PnEjvjHn9U8Baw6eQ
    expected: 11852
    actual:   11850
    average:  118.5
    min:      105
    max:      128
    running similar code in Java (using a different http client though) results in the following
    expected: 94
    actual:   74
    average:  0.74
    min:      0
    max:      25
    How can I figure out where this overhead comes from? And how can I solve it?
    j
    • 2
    • 4
  • g

    GoldenCow

    03/14/2022, 8:00 AM
    Hello, I followed the Kotlin full-stack web app tutorial to make my web app, and I am now working on deploying it to Heroku. I used MongoDB Atlas to connect Heroku and my database, and the code used is very much the same in the tutorial itself. I encountered a problem where when I POST through the frontend, I receive a 403 error. The strange thing is, GET and DELETE requests work just fine, and even when I POST with something like curl, it works perfectly! The only problem is that POST doesn't work from the frontend. When this function is called from the frontend:
    suspend fun addShoppingListItem(shoppingListItem: ShoppingListItem) {
    
        <http://jsonClient.post|jsonClient.post><Unit>(endpoint + ShoppingListItem.path) {
    
    
            contentType(ContentType.Application.Json)
            body = shoppingListItem
    
        }
    
    }
    This is what the server does when it receives a POST request:
    post {
    
        collection.insertOne(call.receive<ShoppingListItem>())
        call.respond(HttpStatusCode.OK)
    
    }
    but this is what I get every time I perform a POST request through my browser. Are there any help or docs I might be able to benefit from?
    r
    • 2
    • 3
  • f

    FunkyMuse

    03/14/2022, 5:05 PM
    Hey guys, is it possible to parse application.conf inside gradle.kts somehow?
    b
    • 2
    • 4
Powered by Linen
Title
f

FunkyMuse

03/14/2022, 5:05 PM
Hey guys, is it possible to parse application.conf inside gradle.kts somehow?
b

Big Chungus

03/14/2022, 8:24 PM
Sure, just add any hocon java lib to buildSrc and parse it like in any other java app
f

FunkyMuse

03/14/2022, 10:33 PM
Thank you, I meant inside build.gradle.kts not in buildSrc? But i doubt it makes a difference to what you've said since it's the same?
b

Big Chungus

03/14/2022, 11:13 PM
Well you declare dependencies in buildSrc to make them available in your buildscripts
f

FunkyMuse

03/15/2022, 10:06 PM
For those who would parse them in the future, make sure you remove prefix and suffix double quotes as it does parse them as strings but with additional quotes
View count: 2