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

    Patrick Jackson

    07/18/2019, 2:45 PM
    is io.ktor.client.features.json.serializer.KotlinxSerializer in another package or gone entirely? updated the ktor version and it is missing now
    e
    • 2
    • 3
  • a

    Alexander

    07/19/2019, 10:45 AM
    Shouldn't event handlers in ktor be a
    suspend
    functions? At the moment I cannot use synchronization primitives (channels, mutexes) inside them.
    • 1
    • 2
  • b

    bitkid

    07/19/2019, 11:05 AM
    is there a clever way to inject my dependencies when using extension functions of Route? atm i have a method like this but i always have to pass through my dependencies to other method calls. this feels a bit clumsy
    Untitled
    👍 1
    e
    e
    d
    • 4
    • 9
  • r

    Rodrigo Silva

    07/19/2019, 11:08 PM
    Hello all 😃. What is the best way to handle validation errors in Ktor? In spring I used the @ControllerAdvice and @ExceptionHandler (). But I'm a little lost here
    d
    c
    • 3
    • 6
  • j

    Jonas Ørting

    07/20/2019, 5:50 PM
    Hi I need to do some basic image processing on the server (scale, crop). Is there a kotlin library for that? If not, what would be the recommended Java library? (I've never worked with Java, and I'm having a hard time figuring out what current best practice is)
    d
    r
    • 3
    • 11
  • c

    carrot

    07/21/2019, 10:31 PM
    Pleased to say that all of Adopt Animals' (https://www.adoptanimals.io/) service level stack (website, backend services) uses Ktor now. It's faster and uses about half the memory of the setup we had previously, but we moved everything over mostly just because it's way more pleasant to work with. Thanks for making some great software 🙂
    👏 11
    :kotlin: 5
    😒uspend: 2
    m
    • 2
    • 2
  • b

    bitkid

    07/22/2019, 8:22 AM
    does anyone have experience with ktor server handling large uploads (filesize up to 10GB)? any important things to look out for, caveats? i remember seeing a user saying that he had problems with the netty engine but i can't find it anymore.
    r
    k
    k
    • 4
    • 4
  • r

    Robin Larsen

    07/22/2019, 6:20 PM
    Greetings! I'm getting some rather weird behavoir running Ktor with Thymeleaf template engine. Everything works fine from the IDE; templates render nicely, even with different containers (Tomcat, Netty, Jetty) But when I deploy to my actualy server running Tomcat 8.5.34, the templates don't work. I get a blank white screen after a few seconds of loading. Inspecting the console I get
    net::ERR_INVALID_CHUNKED_ENCODING 200 (200)
    both in Chrome and Firefox. All other endpoints not using the templates work fine (JSON, plain text) I have other apps running just fine on the same server using Thymeleaf, although the apps are made with SpringBoot. Any ideas?
    c
    • 2
    • 5
  • m

    max.denissov

    07/23/2019, 6:13 AM
    Hello! Who may help with information about how to implement a “response wrapper” pattern in the ktor-client. For example, has a model object User.
    data User(name: String)
    Response from server with a wrapper: Success response:
    {
      "data": {
        "name": "Mark Watney"
      },
      "error": null
    }
    Business error respose:
    {
    
     	"data": null
     	"error": { ... }
     }
    In android I can use something like an interceptor or an adapter in library like Retrofit, but what about ktor-client?
    m
    • 2
    • 5
  • n

    Nikolai

    07/23/2019, 3:48 PM
    Hi, everyone How can I perform an http request (post/get) from ktor server to another server api? A short example will be perfect.
    s
    v
    • 3
    • 7
  • h

    Hamza

    07/24/2019, 11:05 AM
    POST <http://localhost:1296/search> 415 (Unsupported Media Type)
    m
    c
    • 3
    • 8
  • a

    Alexander Potukar

    07/24/2019, 1:04 PM
    What is the current status of ktor and automatic creation of OpenAPI Spec aka swagger files based on source code? Does anyone know if this is possible now? To clarify: I don’t want API first but API creation based on code.
    ➕ 8
    s
    • 2
    • 1
  • s

    Sergioedcigreja

    07/24/2019, 1:49 PM
    Hey guys.. what's the state of iOS websockets?
    e
    • 2
    • 2
  • s

    Slackbot

    07/24/2019, 1:58 PM
    This message was deleted.
    c
    s
    • 3
    • 2
  • r

    rahulrav

    07/25/2019, 12:11 PM
    I am trying to add cache control headers to static pages served via the
    resources
    handler. For some reason I don’t see the correct response headers. What am I doing wrong ? https://github.com/tikurahul/rahulrav-com/blob/master/src/main/kotlin/com/rahulrav/Application.kt#L47 https://github.com/tikurahul/rahulrav-com/blob/master/src/main/kotlin/com/rahulrav/RequestHandlers.kt#L25
    ➕ 1
    c
    • 2
    • 4
  • s

    sonofblip

    07/25/2019, 3:06 PM
    Anyone have experience with generating swagger docs with ktor?
    m
    • 2
    • 2
  • h

    Hamza

    07/25/2019, 4:10 PM
    get("/{*}") {
                call.respond("hello")
            }
    didn't work for
    /
    and
    /{anything}/{something}
    c
    n
    • 3
    • 5
  • s

    sonofblip

    07/25/2019, 6:43 PM
    Is there a way to apply ktor annotation classes across whole projects? I’m tired of having to put
    @KtorExperimentalLocationsAPI
    or
    @KtorExperimentalAPI
    over everything in order to remove IntelliJ warnings.
    c
    y
    k
    • 4
    • 7
  • s

    Sergioedcigreja

    07/26/2019, 10:52 AM
    Hey guys, quick question: Im getting a networkOnMainThread error when I do client.close().. what's the best way to close the client?
    👀 1
    e
    e
    • 3
    • 8
  • f

    Fail

    07/26/2019, 2:27 PM
    Why
    expectSuccess = false
    not working at 1.2.2? On Ktor multiplatform I catch Platform exception I tried the following options:
    HttpClient {
                expectSuccess = false
    and
    HttpClient {
    HttpResponseValidator {
                    validateResponse {response ->
                        if (response.status.value!=200) {
                            throw ResponseException(response)
                        }
                    }
    
                }
    And
    ResponseException
    not catched. Only
    Exception
    not Solved 😞
    e
    • 2
    • 4
  • s

    spierce7

    07/27/2019, 10:17 PM
    I'm trying to create a redirect, so that all bad urls redirect the user back to my main site. I've noticed that this ends up interfering with my
    static
    block for some image requests (i.e.
    /favicon-32x32.png
    ) aren't found and get returned with the redirect, but when I comment out the
    redirectUnknown
    function, it works fine. It's odd because my
    static
    block is placed before
    redirectUnknown
    . Does anyone know of a better way to do this?
    fun Route.redirectUnknown() {
        // Unknown path - redirect back to main site
        get("*") {
            val domain = call.request.domain()
            val port: String = run {
                val port = call.request.port()
                if (port == 80 || port == 443) "" else ":$port"
            }
    
            val redirectUrl: String = if (BuildUtil.isDev) {
                val scheme = call.request.origin.scheme
    
                if (domain.value == "localhost" || domain.isIpAddress()) {
                    "$scheme://$domain$port/"
                } else {
                    "$<scheme://www>.$domain$port/"
                }
            } else {
                "<https://www>.$domain$port/"
            }
    
            call.respondRedirect(redirectUrl)
        }
    }
    b
    • 2
    • 2
  • d

    Dominaezzz

    07/29/2019, 9:55 AM
    When I do
    val response = client.get<HttpResponse>(....)
    , do I also have to do
    response.close()
    ? Can't find docs and the samples don't give an indication.
    :yes: 1
    q
    • 2
    • 2
  • s

    spierce7

    07/29/2019, 8:40 PM
    If I wanted to intercept all server requests that aren't https, and aren't prefixed with
    www
    , and redirect to the
    <https://www>.
    version of my site - what would be the best way to do that?
    g
    d
    c
    • 4
    • 6
  • b

    Bino

    07/30/2019, 8:54 AM
    Does anyone know, how I can integrate a
    dns-sd
    or
    zeroconf/bonjour
    into ktor? I would like to announce the ktor service in a local network without setting the ip/host on the client.
    • 1
    • 1
  • t

    Thomas

    07/30/2019, 6:58 PM
    Hello,
    ResponseException
    is not serializable, it throws a
    NotSerializableException
    . This is because of the
    response
    field. Can this be changed so it is serializable? https://github.com/ktorio/ktor/blob/178479ba392524d37193fcf2f6b30f570a0a3ba7/ktor-client/ktor-client-core/common/src/io/ktor/client/features/DefaultResponseValidation.kt#L51
    e
    • 2
    • 12
  • r

    Robert Menke

    07/31/2019, 12:14 AM
    Ha omitting
    response.close()
    caused one of our servers to run out of memory today @Dominaezzz. Just fixed it and fortunately had no downtime because ECS is pretty nice 🙂.
    🤔 1
    e
    c
    d
    • 4
    • 6
  • m

    Melih Aksoy

    07/31/2019, 11:20 AM
    Hey all ! I’m using Ktor in a multiplatform library, where I need to post some json body to url. My current setup for dependencies is
    sourceSets {
            commonMain {
                dependencies {
                    implementation 'org.jetbrains.kotlin:kotlin-stdlib-common'
                    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$coroutine_version"
                    implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$serializer_version"
    
                    implementation "io.ktor:ktor-client-core:$ktor_version"
                    implementation "io.ktor:ktor-client-json:$ktor_version"
                }
            }
            androidMain {
                dependencies {
                    implementation 'org.jetbrains.kotlin:kotlin-stdlib'
                    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutine_version"
                    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutine_version"
                    implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$serializer_version"
    
                    implementation "io.ktor:ktor-client-android:$ktor_version"
                    implementation "io.ktor:ktor-client-json-jvm:$ktor_version"
                }
            }
            iosMain {
                dependencies {
                    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-native:$coroutine_version"
                    implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$serializer_version"
    
    
                    implementation "io.ktor:ktor-client-ios:$ktor_version"
                    implementation "io.ktor:ktor-client-json-native:$ktor_version"
                }
    
            }
        }
    I’m having trouble with keeping client in common. If I use client in common module as just an
    HttpClient()
    , without features, I’m getting class cast exception as in https://github.com/ktorio/ktor/issues/997. Defining content type does not solve it, but I can add
    JsonFeature
    to my client. This ends up crashing in Android tho:
    Caused by: java.lang.IllegalStateException: Fail to find serializer. Consider to add one of the following dependencies: 
         - ktor-client-gson
         - ktor-client-json // <- Oh well, it's actually there isn't it ?
         - ktor-client-serialization
    As seen above in dependencies, I’m including
    io.ktor:ktor-client-json
    in common, but it does not contain any serializer that I can assign in
    install(JsonFeature) {
                serializer = ????
    }
    block. If I define serializer as
    expect
    and try to implement
    actual
    for Android, it’s fine, but again, I can’t find any for iOS implmentation (
    io.ktor:ktor-client-json-native
    ). What is the right way to do this by using
    kotlinx.serialization
    for both platforms ?
    d
    m
    • 3
    • 13
  • b

    Big Chungus

    08/01/2019, 3:38 PM
    As in ktor clent based on okhttp
    t
    • 2
    • 4
  • c

    cy

    08/01/2019, 6:33 PM
    📣 ktor
    1.2.3
    has been published * JS websocket bugs fixes and improvements * Eliminated Java9's Base64 implementation (useful for older JDK and Android) * Fixed bug of adding unexpected trailing slash (#1201) (#1206) * Improved apache and okhttp client engines performance * Fixed client response body cancellation * Added client response streaming on nodejs * Deprecated old client
    BasicAuth
    * Introduced a flag to send auth without negotiation * Added server kotlinx.serialization initial support (
    SerializationConverter
    ) * Client TLS implementation fixes: cancellation and error handling. * Added web assembly content type. * Prohibited server double request content
    call.receive
    . * Introduce
    DoubleReceive
    feature that makes it work. * Server CORS support fixed and improved * Added initial kotlinx.serialization support for server including receiving generic collections. * Introduced
    ktor-bom
    for better dependency management. * Improved jetty server engine configuration to enable manual connectors setup. * Fixed client memory leak (#1223). * Upgraded Jetty, Netty and utility libraries. * Kotlin 1.3.41 ⚠️ Breaking changes/Migration steps: * CORS doesn’t allow non-simple request body content types anymore by default * to allow extra content types such as json, enable
    allowNonSimpleContentTypes
    * At least Kotlin 1.3.41 IS REQUIRED
    🎉 24
    👏 5
    ❤️ 9
    d
    • 2
    • 1
  • a

    andrew

    08/01/2019, 9:54 PM
    Is there a builtin way to adapt a response?
    d
    • 2
    • 3
Powered by Linen
Title
a

andrew

08/01/2019, 9:54 PM
Is there a builtin way to adapt a response?
d

Dominaezzz

08/01/2019, 10:01 PM
CustomSerializer probably. Better luck in #serialization
a

andrew

08/01/2019, 10:03 PM
thank you
so many channels, here 😛
View count: 2