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

    bitkid

    04/22/2019, 5:41 PM
    or maybe better phrased, why can't you make extension functions to Routing suspend and use it in routing { }
    • 1
    • 1
  • h

    hdarritchon

    04/23/2019, 6:37 AM
    Hi @Nezteb May be you can have a look to https://github.com/ktorio/ktor/issues/453, inside this issue, you have a link to a Github repo that should have something you want https://github.com/nielsfalk/ktor-swagger. Give us a feedback.
    n
    j
    • 3
    • 2
  • t

    Thomas

    04/23/2019, 10:04 AM
    Is there a way to use Ktor 1.2.0 alpha with Kotlin 1.3.30? Could you make a new release with 1.3.30 support?
    e
    v
    • 3
    • 7
  • r

    ribesg

    04/23/2019, 1:48 PM
    I may have missed something, how do you do a post request without expecting a response body with the Http client?
    <http://client.post|client.post><Unit>(...)
    or something like that?
    :yes: 1
    g
    b
    • 3
    • 5
  • n

    Nikky

    04/23/2019, 10:49 PM
    can ktor (server) be compiled to kotlin-js or only the client ? my intended usecase is a fallback integrated server for a boardgame client in js/jfx
    g
    b
    • 3
    • 12
  • p

    pardom

    04/24/2019, 1:49 PM
    The stacktrace shows a call to
    lookupSerializerByType
    which does not look for serializers in
    listMappers
    (where
    registerList<Long>()
    places the serializer).
    e
    • 2
    • 4
  • h

    hdarritchon

    04/24/2019, 7:34 PM
    @Dennis Schröder I am not too sure to understand your question. You mean to have a component (your packed jar or fatjar piece of code) modifying the routes of an app that includes as a dependency your component ?
    d
    • 2
    • 1
  • s

    serebit

    04/24/2019, 7:41 PM
    Are native (linux, macOS, mingw) sockets planned for 1.2.0?
    d
    • 2
    • 2
  • r

    ribesg

    04/25/2019, 7:23 AM
    There is a huge problem with
    ktor-client-android
    , I get a
    400
    with a nice json response on Android L/21 to a request but the client never actually sent the request to the server, it responded alone with this:``` { "message": "Bad request", "status": 400 }``` I can’t provide a way to reproduce the issue so I don’t know if it’s worth to open one on Github. The problem doesn’t occur with Android Q/29. I worked around the issue by switching to
    ktor-client-okhttp
    e
    • 2
    • 2
  • r

    rrader

    04/25/2019, 11:26 AM
    How do you build your API for example for registration, there is password field, it has some constraints(length, allowed characters) are these constraints also hardcoded on client side, or do you have and endpoint in the API to retrieve constraints information?
    r
    d
    g
    • 4
    • 4
  • a

    Antanas A.

    04/25/2019, 11:50 AM
    Hi, is it possible to do "forward" (inner call) with ktor? Example if I have some action which receives GET requests as an array, and it must return an array of all responses. How can this be implemented with ktor?
    n
    • 2
    • 1
  • s

    Steven

    04/25/2019, 12:04 PM
    Hi, i was wondering if ktor client-side was compatible with all api versions of android? I saw in the FAQ that ktor servers were only for android 27 and up, but i didn't see anything for ktor clients. I am asking because i have a connection "closed by peer" error on kitkat but works on other versions
    e
    r
    • 3
    • 11
  • h

    hyukchan

    04/25/2019, 4:20 PM
    Hi guys, I'm building a server side application. I would like to know what is the best practice to avoid having a big routing resource file ? How can we divide ? Imagine I have those urls for my API: GET /animal POST /animal GET /animal/:id POST /animal/:id and 20 URLs more starting by /animal.... I think having a "AnimalResource.kt" for all those url is not the best practice. How can I do ?
    k
    l
    h
    • 4
    • 7
  • t

    tjohnn

    04/25/2019, 7:02 PM
    Documentation on
    invoke()
    warned against overusing it, right now I am using it for all my uses cases e.g
    class CreateNewSubCategory @Inject constructor(private val subcategoryRepository: SubCategoryRepository){
        suspend operator fun invoke(category: Subcategory): Int = subcategoryRepository.createSubCategory(category)
    }
    Is there any detriment to that?
    d
    • 2
    • 4
  • n

    napperley

    04/26/2019, 1:41 AM
    Been getting some strange errors from Jetty:
    2019-04-26 13:35:26 DEBUG ManagedSelector:395 - Selector sun.nio.ch.EPollSelectorImpl@3127e5fa waiting with 1 keys
    2019-04-26 13:35:26 DEBUG IdleTimeout:156 - SocketChannelEndPoint@1c0f19b5{/192.168.10.40:45496<->/192.168.10.40:10001,OPEN,fill=-,flush=-,to=5/30000}{io=0/0,kio=0,kro=0}-><null> idle timeout check, elapsed: 5 ms, remaining: 29995 ms
    2019-04-26 13:35:26 DEBUG SslContextFactory:1645 - Customize sun.security.ssl.SSLEngineImpl@26e0da09
    2019-04-26 13:35:26 DEBUG PreEncodedHttpField:64 - HttpField encoders loaded: [org.eclipse.jetty.http2.hpack.HpackFieldPreEncoder@172d9369]
    2019-04-26 13:35:26 DEBUG ManagedSelector:671 - 
    java.lang.ExceptionInInitializerError
    	at org.eclipse.jetty.server.HttpConnection.<clinit>(HttpConnection.java:56)
    	at org.eclipse.jetty.server.HttpConnectionFactory.newConnection(HttpConnectionFactory.java:85)
    	at org.eclipse.jetty.server.SslConnectionFactory.newConnection(SslConnectionFactory.java:95)
    	at org.eclipse.jetty.server.ServerConnector$ServerConnectorManager.newConnection(ServerConnector.java:532)
    	at org.eclipse.jetty.io.ManagedSelector.createEndPoint(ManagedSelector.java:227)
    	at org.eclipse.jetty.io.ManagedSelector.access$1500(ManagedSelector.java:60)
    	at org.eclipse.jetty.io.ManagedSelector$Accept.run(ManagedSelector.java:667)
    	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:762)
    	at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:680)
    	at java.base/java.lang.Thread.run(Thread.java:834)
    Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
    	at org.eclipse.jetty.http.PreEncodedHttpField.<clinit>(PreEncodedHttpField.java:71)
    	... 10 more
    2019-04-26 13:35:26 WARN  ManagedSelector:679 - java.lang.ExceptionInInitializerError
    2019-04-26 13:35:26 DEBUG ManagedSelector:680 - 
    java.lang.ExceptionInInitializerError
    	at org.eclipse.jetty.server.HttpConnection.<clinit>(HttpConnection.java:56)
    	at org.eclipse.jetty.server.HttpConnectionFactory.newConnection(HttpConnectionFactory.java:85)
    	at org.eclipse.jetty.server.SslConnectionFactory.newConnection(SslConnectionFactory.java:95)
    	at org.eclipse.jetty.server.ServerConnector$ServerConnectorManager.newConnection(ServerConnector.java:532)
    	at org.eclipse.jetty.io.ManagedSelector.createEndPoint(ManagedSelector.java:227)
    	at org.eclipse.jetty.io.ManagedSelector.access$1500(ManagedSelector.java:60)
    	at org.eclipse.jetty.io.ManagedSelector$Accept.run(ManagedSelector.java:667)
    	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:762)
    	at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:680)
    	at java.base/java.lang.Thread.run(Thread.java:834)
    Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
    	at org.eclipse.jetty.http.PreEncodedHttpField.<clinit>(PreEncodedHttpField.java:71)
    	... 10 more
    2019-04-26 13:35:26 DEBUG QueuedThreadPool:682 - ran org.eclipse.jetty.io.ManagedSelector$Accept@229ba41d
    • 1
    • 4
  • r

    Rainer Schlonvoigt

    04/26/2019, 8:05 AM
    the following code never prints anything for me:
    g
    • 2
    • 12
  • r

    Rainer Schlonvoigt

    04/26/2019, 8:06 AM
    the "Jooooo" is printed, but never 'request config'
    e
    • 2
    • 8
  • a

    Abbas A

    04/26/2019, 2:31 PM
    Hi, I have a question regarding mapping routing with special characters, example:
    get("/item/{itemId}/search?address[lat]={lat}")
    unfortunately ktor can’t map it, from server I see that request was encoded as:
    /item/1234/search?address%5Blat%5D={lat}
    is it issue or I do something wrong? I tried to find something here or in docs, what I found is:
    <https://ktor.io/servers/features/routing.html#tracing>
    after applying trace to routing:
    /item/1234/search?address[lat]={lat}, segment:3 -> FAILURE "Selector didn't match" @ /item/1234/search?address%5Blat%5D={lat})
    n
    • 2
    • 2
  • w

    wakingrufus

    04/26/2019, 4:41 PM
    hello, I have a question about client error handling. if i call
    request<HttpResponse>
    I can check for status and other things in order to do my own error handling, but then i can't leverage the built in Json deserialization of my object. but if i call
    request<MyObject>
    in order to get the deserialization, it is not clear how to check and handle errors. I am looking for something like Fuel's `Result.fold`:
    inline fun <X> fold(success: (V) -> X, failure: (E) -> X): X = when (this) {
            is Success -> success(this.value)
            is Failure -> failure(this.error)
        }
    . is there something like this in ktor?
    o
    • 2
    • 3
  • m

    Marcin Wisniowski

    04/27/2019, 3:40 PM
    (Succeeded differently, but the questions still stands why the example from the documentation doesn't work, the
    formData
    function is very nice, why doesn't it work?)
    b
    • 2
    • 1
  • m

    Marcin Wisniowski

    04/27/2019, 3:49 PM
    Found the issue, it has to be
    MultiPartFormDataContent
    , not
    FormDataContent
    as the documentation wrongly states.
    b
    e
    • 3
    • 6
  • n

    napperley

    04/28/2019, 4:40 AM
    Keep on seeing Connection reset by peer errors (looks as though there is a issue on the client side) in the server logs which are caused by the Android client (but not Postman in testing). The server uses Ktor 1.1.2, Kotlin 1.3.20, Zulu JDK 11.0.2, and Netty as the web engine. Below is the server error:
    DEBUG Application:102 - I/O operation failed
    java.io.IOException: Connection reset by peer
    	at java.base/sun.nio.ch.FileDispatcherImpl.read0(Native Method)
    	at java.base/sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:39)
    	at java.base/sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:276)
    	at java.base/sun.nio.ch.IOUtil.read(IOUtil.java:233)
    	at java.base/sun.nio.ch.IOUtil.read(IOUtil.java:223)
    	at java.base/sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:358)
    	at io.netty.buffer.PooledUnsafeDirectByteBuf.setBytes(PooledUnsafeDirectByteBuf.java:288)
    	at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1108)
    	at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:345)
    	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:148)
    	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:645)
    	at io.netty.channel.nio.NioEventLoop.processSelectedKeysPlain(NioEventLoop.java:545)
    	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:499)
    	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:459)
    	at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884)
    	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
    	at java.base/java.lang.Thread.run(Thread.java:834)
    On the Android client side it looks as though there is a issue on the server side with Socket Closed (https://stackoverflow.com/questions/24620953/android-error-java-net-socketexception-socket-closed) errors appearing in the logs. Encountering bi-directional issues here where it isn't clear which side is causing the issue 😕. How do I know if the issue is on the server side?
    • 1
    • 2
  • j

    Jens Baitinger

    04/28/2019, 12:05 PM
    Hi, im trying to compile ktor from master, but im getting the error message
    Cannot change attributes of configuration ':ktor-server:ktor-server-jetty:ktor-server-jetty-test-http2:posixApiElements' after it has been resolved
    Anyone who knows a quickfix for that?
    e
    • 2
    • 3
  • a

    andrew

    04/28/2019, 3:25 PM
    with ktor, are we able to access the response body at all if we use a serialized class as the response type?
    🇳🇴 1
    j
    d
    e
    • 4
    • 7
  • d

    darkmoon_uk

    04/29/2019, 11:36 AM
    It looks like if I want to use Ktor/iOS then I have to stay with Kotlin
    1.3.20
    at the moment, is that correct?
    e
    • 2
    • 5
  • d

    darkmoon_uk

    04/29/2019, 1:39 PM
    Are Websockets supported for iOS in
    1.1.5
    ? There's a
    ktor-client-websocket-1.1.5
    artifact. ... but no
    1.1.5
    for any of the platform-specific
    ktor-client-websocket-1.1.5-*
    artifacts... ?
    e
    d
    • 3
    • 6
  • c

    Cláudio Bartolomeu

    04/29/2019, 3:40 PM
    Hi, where can I find more information about HttpClient pipelines and it's corresponding phases?
    b
    • 2
    • 1
  • k

    Kevin Schmeichel

    04/29/2019, 6:55 PM
    I'm a bit confused by
    Locations
    - why isn't this just built into
    Routing
    ?
    r
    b
    • 3
    • 5
  • b

    bitkid

    04/29/2019, 9:55 PM
    does jwt auth work with the location api? i do something like routing { somethingWitoutAuth() authenticate("jwt") { routing { somethingWithAuth(); } } }
    o
    • 2
    • 8
  • b

    bitkid

    04/29/2019, 9:59 PM
    it just seems to ignore it
    k
    • 2
    • 6
Powered by Linen
Title
b

bitkid

04/29/2019, 9:59 PM
it just seems to ignore it
meaning i expect it to return Unauthorized in the test but it doesn't. whereas when i dont use the locations api it works
k

Kevin Schmeichel

04/29/2019, 10:23 PM
This is basically what I was trying to get at with my last post - it seems like a bad idea to have 2 different ways to do routing...
b

bitkid

04/29/2019, 10:42 PM
i always thought the locations api is just some annotation sugar + json mapping over the normal routing
k

Kevin Schmeichel

04/29/2019, 10:55 PM
oh, maybe - I haven't looked that closely at the code. as a newcomer to ktor, it does seem a bit confusing though, having 2 separate services to do basically the same thing.
b

bitkid

04/29/2019, 11:09 PM
and it can totally be that my example is wrong and it does actually work 😉
k

Kevin Schmeichel

04/30/2019, 12:07 AM
please post if you find out either way.
View count: 3