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

    Antero Duarte

    01/10/2019, 11:59 AM
    Hey! So I just came across this for the first time after using Ktor for a while, and I'm sure someone will have run into this before and knows the most idiomatic way of solving it. I've got a route that I want to handle for both put and post, and I was wondering if there's a way of handling both methods without using the more general
    handle {}
    , because I really like the DSL for
    get{}
    ,
    put{}
    ,
    post{}
    ...etc
    o
    3 replies · 2 participants
  • c

    coder82

    01/10/2019, 12:41 PM
    are CORS enabled by default?
    c
    1 reply · 2 participants
  • h

    hmole

    01/10/2019, 1:59 PM
    Is there an example of an
    ApplicationFeature
    that catches all errors inside routing, and depending on the exception type throws again or handles if to return normal response?
    c
    1 reply · 2 participants
  • a

    alexfacciorusso

    01/10/2019, 5:13 PM
    Hi guys! I’m configuring Ktor in my mpp project. When I run it in Android, it works perfectly, but when I try to call an API in iOS (Native), the error says:
    An operation is not implemented: Obtaining serializer from KClass is not available on native due to the lack of reflection. Use .serializer() directly on serializable class.
    h
    1 reply · 2 participants
  • z

    zjuhasz

    01/11/2019, 11:48 AM
    I don’t see kotlinx.serialization artifact for ktor server on the list of artifacts here https://ktor.io/quickstart/artifacts.html Are there some artifacts not listed or kotlinx.serialization only available for ktor clients and not servers?
    e
    3 replies · 2 participants
  • t

    Tobi

    01/11/2019, 2:54 PM
    Hey folks, I am trying to use
    io.ktor.client.engine.mock.MockEngine
    in my multiplatform project
    commonTest
    source set in order to test my engine configuration, but I can’t import it 🤔 I added
    implementation "io.ktor:ktor-client-mock:$ktor_version"
    to my
    commonTest.dependencies
    closure in the multiplatform
    build.gradle
    , but it seems like the dependency can’t be resolved. Any ideas?
    s
    5 replies · 2 participants
  • c

    coletz

    01/11/2019, 5:52 PM
    I mean that this is the code I use with retrofit, I need to do the same thing with ktor. (I don't want to use the part of code from retrofit, I'd like to remove retrofit at all)
    m
    2 replies · 2 participants
  • c

    coletz

    01/11/2019, 7:30 PM
    Is someone using ktor 1.1.1 on android? If I try this code
    GlobalScope.launch {
                try {
                    val res = HttpClient().post<String> {
                        url("<http://172.16.94.217:3000/>")
                        body = "HELLO WORLD!"
                    }
                    Log.e("RES", res)
                } catch (e: Exception){
                    e.printStackTrace()
                }
            }
    I get a 400 bad request, while removing the body I get a response. The problem is not server side, since the server is not even receiving a call if I add the body Am I the only one getting this behaviour? Hadn't tried with older version atm
    m
    2 replies · 2 participants
  • m

    Marc Knaup

    01/12/2019, 4:42 PM
    What is ktor trying to tell me here? How can I debug this?
    2019-01-12 17:37:02.237 WARN  i.n.u.c.AbstractEventExecutor - A task raised an exception. Task: DispatchedContinuation[DispatcherWithShutdown@60dcb7b6, Continuation at com/github/fluidsonic/fluid/mongo/CoroutineMongoCollection.insertOne(CoroutineMongoCollection.kt:250)@735b9ac6]
    kotlinx.coroutines.DispatchException: Unexpected exception running DispatchedContinuation[DispatcherWithShutdown@60dcb7b6, Continuation at com/github/fluidsonic/fluid/mongo/CoroutineMongoCollection.insertOne(CoroutineMongoCollection.kt:250)@735b9ac6]
    	at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:237)
    	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
    	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404)
    	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:463)
    	at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884)
    	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
    	at java.lang.Thread.run(Thread.java:748)
    Caused by: java.lang.IllegalStateException: No more continuations to resume
    	at io.ktor.util.pipeline.SuspendFunctionGun.resumeRootWith(PipelineContext.kt:197)
    	at io.ktor.util.pipeline.SuspendFunctionGun.loop(PipelineContext.kt:168)
    	at io.ktor.util.pipeline.SuspendFunctionGun.access$loop(PipelineContext.kt:63)
    	at io.ktor.util.pipeline.SuspendFunctionGun$continuation$1.resumeWith(PipelineContext.kt:118)
    	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:45)
    	at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:233)
    	... 6 common frames omitted
    t
    c
    8 replies · 3 participants
  • j

    jdiaz

    01/12/2019, 10:14 PM
    Does ktor support native client and json? I can't get it to work with these dependencies (I can't instantiate an
    HttpClient
    and the curl dependency shows as red in IntelliJ)
    implementation "io.ktor:ktor-client-core:1.1.1"
                    implementation "io.ktor:ktor-client-core-native:1.1.1"
                    implementation "io.ktor:ktor-client-json-native:1.1.1"
                    implementation "io.ktor:ktor-client-curl:1.1.1"
    s
    e
    2 replies · 3 participants
  • h

    hmole

    01/13/2019, 12:12 PM
    Is ktor autoreload stable/supposed to work in most cases? I'm trying it out and immediately getting problems with file locks.
    1 reply · 1 participant
  • a

    alexfacciorusso

    01/13/2019, 5:09 PM
    anyone has any clue on this message I sent some days ago? Cheers! https://kotlinlang.slack.com/archives/C0A974TJ9/p1547224415261500
    s
    e
    4 replies · 3 participants
  • z

    zjuhasz

    01/14/2019, 10:24 AM
    Is it possible to change the
    CoroutineDispatcher
    used in ktor websocket? I’d like to consume the messages on a single threaded dispatcher. As a workaround I am resending the messages on a new channel and consuming them from a coroutine I launched on the dispatcher I want.
    1 reply · 1 participant
  • v

    vonox7

    01/14/2019, 2:46 PM
    Do you have any clues what’s going on here? Or how to further debug this issue?
    c
    1 reply · 2 participants
  • s

    sngrekov

    01/14/2019, 4:26 PM
    Are there any working sample with ktor multiplatform 1.1.1 on ios?
    e
    3 replies · 2 participants
  • a

    ansman

    01/14/2019, 8:46 PM
    How does one pick a server engine? Is there any benchmarks or other data that might help my decision?
    ➕ 8
    1 reply · 1 participant
  • y

    yuya_horita

    01/15/2019, 8:16 AM
    Just simple get request.
    e
    22 replies · 2 participants
  • c

    ctierney

    01/15/2019, 6:17 PM
    Question about routing path parameters: Suppose I have a route:
    get("/foo/{param1}/bar" { ... }
    When I access
    call.parameters["param1"]
    the type is
    String?
    . My question is, can this ever actually be null? What situation would lead to a request with no value for
    param1
    being routed to that handler? (I am avoiding the Locations feature for now since it is marked experimental.)
    f
    2 replies · 2 participants
  • v

    vonox7

    01/15/2019, 8:23 PM
    Hi, Is it expected behaviour that in the following example
    <http://localhost:8090/asdf>
    leads to the ADMIN route? Shoudn’t no route be taken?
    embeddedServer(Netty, port = 8090) {
          // <http://localhost:8090/admin-prefix-hello> --> "ADMIN" (OK)
          // <http://localhost:8090/subdirectory/hello> --> "Wildcard 404" (OK)
          // <http://localhost:8090/asdf> --> "ADMIN" (WHAT? Why did it take that route?)
          install(Routing) {
            route("admin-prefix-{...}", HttpMethod.Get) {
              handle {
                call.respond("ADMIN")
              }
            }
            route("subdirectory") {
              route("{...}", HttpMethod.Get) {
                handle {
                  call.respond("Wildcard 404")
                }
              }
            }
          }
        }.start()
    o
    2 replies · 2 participants
  • a

    ansman

    01/15/2019, 9:24 PM
    Are you supposed to create different `HttpClient`s for different API or is it recommend to share a single instance across your service? It would be nice to set default headers and stuff but when using multiple APIs that isn’t ideal since you have to check the URL host before doing anything
    e
    5 replies · 2 participants
  • w

    wilyarti

    01/16/2019, 6:05 AM
    Hi guys I am trying to get ktor http client to POST a request to an API with FormURLEncoded. I am getting the following error: io.ktor.http.UnsafeHeaderException: Header Content-Type is controlled by the engine and cannot be set explicitly Here is my data class: data class getAuth( val client_id: String, val client_secret: String, val grant_type: String = "client_credentials", val scope: String = "NSMS" ) Here is my constructor: val message = client.post<Unit> { url(URL("https://tapi.telstra.com/v2/oauth/token")) contentType(ContentType.Application.FormUrlEncoded) body = getAuth(client_id = "overriddenkey", client_secret = "overridenpass") } Is there something I am missing here? How do I go about sending the POST with Content-Type: application/x-www-form-urlencoded ?
    👀 1
    e
    2 replies · 2 participants
  • s

    spierce7

    01/16/2019, 9:38 PM
    Hey, if I wanted to override the exception from ktor for BadResponseStatus and turn it into a different exception, can I do that in a ktor feature?
    ➕ 1
    e
    e
    6 replies · 3 participants
  • l

    louiscad

    01/17/2019, 9:29 AM
    Hi, is ktor backend side node JS compatible?
    o
    n
    5 replies · 3 participants
  • g

    gotoOla

    01/17/2019, 3:52 PM
    Hi! Just found out about the use-extension (have no idea how I’ve missed that before) and I was wondering if there’s any reason why this is not used by default in the ktor-client? I.e. wouldn’t an auto close feature make a nicer api? The reason why I am asking is that we had a memory leak which was a result of us not closing the response and I was thinking that this might be the case for others as well
    g
    3 replies · 2 participants
  • w

    wilyarti

    01/19/2019, 9:46 AM
    I know this is beyond the scope of ktor but would it be possible to run a process that is on an infinite loop as a co-routine spawned by a route (or a background thread launched every X minutes)? I ask as I am currently running 2 jars and they both share a lot of libraries... If I could start/stop it from a route that would be great awesome.
    g
    1 reply · 2 participants
  • a

    adeln

    01/20/2019, 8:18 AM
    hey folks! what do you use these days for ktor server engine? Netty or CIO ?
    a
    t
    +1
    6 replies · 4 participants
  • h

    hyukchan

    01/21/2019, 12:40 PM
    Does someone know how to use multiple conf files for Ktor project ?
    r
    7 replies · 2 participants
  • m

    Matt

    01/23/2019, 3:21 PM
    Also: we noticed that things like
    Cookie.expires
    has become a
    GMTDate
    -- what was the thinking behind moving away from standard Java date types to a homebrewed date API?
    d
    b
    4 replies · 3 participants
  • a

    Alexander

    01/23/2019, 4:04 PM
    Don't know whether it is problem of
    K/N
    or
    ktor
    . When I add next dependencies to my program
    commonMain {
                dependencies {
                    implementation "org.jetbrains.kotlin:kotlin-stdlib-common"
    
                    implementation "io.ktor:ktor-client-core:1.1.1"
                    implementation "io.ktor:ktor-client-json:1.1.1"
                }
            }
            linuxMain {
                dependencies {
                    implementation "io.ktor:ktor-client-json-native:1.1.1"
                }
            }
    even
    K/N
    executable with an empty main function crashes on exit with next assertion:
    /opt/buildAgent/work/4d622a065c544371/runtime/src/main/cpp/Memory.cpp:1129: runtime assert: Memory leaks found
    zsh: abort (core dumped)  ./build/bin/linux/main/debug/executable/kafka-connect-rest-client.kexe
    r
    2 replies · 2 participants
  • j

    jkbbwr

    01/23/2019, 11:56 PM
    Exception in thread "main" io.ktor.http.cio.ParserException: No HTTP header value provided for name X-Accepted-OAuth-Scopes:
    Anyone how I get client to ignore empty headers
    c
    3 replies · 2 participants
Powered by Linen
Title
j

jkbbwr

01/23/2019, 11:56 PM
Exception in thread "main" io.ktor.http.cio.ParserException: No HTTP header value provided for name X-Accepted-OAuth-Scopes:
Anyone how I get client to ignore empty headers
https://github.com/ktorio/ktor/issues/853
c

cy

01/24/2019, 10:09 PM
Fixed in 1.1.2
j

jkbbwr

01/24/2019, 11:18 PM
Wicked sauce.
View count: 3