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

    03/16/2020, 2:39 PM
    hi! does ktor have url(location) function which takes x-forward-for, x-proto etc into account?
    • 1
    • 1
  • n

    napperley

    03/16/2020, 9:50 PM
    Looks as though the Ktor KotlinX Serialisation library is causing a InvalidMutablityException to be thrown.
    ➕ 1
    c
    e
    • 3
    • 7
  • c

    cy

    03/17/2020, 9:38 AM
    📣 new ktor IDEA plugin has been released with experimental locations support with inspections and intentions. Please note that the minimal IDEA version is 2018.3.6. See video in the thread :thread-please:
    🤘 3
    👍 3
    🎉 7
    g
    l
    • 3
    • 7
  • s

    spierce7

    03/18/2020, 4:49 AM
    Does Ktor offer the ability to set javascript request timeouts? I can’t seem to find it.
    e
    • 2
    • 2
  • r

    ribesg

    03/18/2020, 9:25 AM
    The
    ByteReadChannel
    passed as
    response.content
    inside a
    ResponseObserver
    is now cancelled after updating from Ktor Client 1.3.0 to 1.3.2, what are we supposed to do with that?
    👀 1
    e
    • 2
    • 12
  • g

    gregorbg

    03/18/2020, 4:14 PM
    Having a problem with cross-site POST requests. I installed the
    CORS
    feature as per https://ktor.io/servers/features/cors.html and everything works for
    GET
    . However with
    POST
    it seems that Chrome (version 80.0.3987.106) does not send the
    Origin
    header, so the ktor intercept function does not reply with the
    Access-Control-Allow-Origin
    header as it should. If I enforce the response header through the
    DefaultHeaders
    feature,
    POST
    works but then for
    GET
    Chrome complains because it does send the
    Origin
    header there and so with
    CORS
    +
    DefaultHeaders
    feature the response header is being set twice (and Chrome doesn't like that...). Any clue how I can work around this issue without waiting for Google to fix their stuff? EDIT: Not only does Chrome not send
    Origin
    headers when `POST`ing by default, it also explicitly removes them when I instruct my frontend (JavaScript
    fetch
    ) to send an
    Origin
    header along with the request.
    g
    • 2
    • 3
  • r

    Rui

    03/18/2020, 10:37 PM
    Hi, if I want to make a bunch of HTTP requests at the same time, is it better to create a new HTTP client for each request or is it ok to let these request share a same client?
    r
    • 2
    • 4
  • c

    chandrut

    03/19/2020, 6:48 AM
    I am in need of KTOR crud api for 3 entities - should I hand write it
    e
    v
    • 3
    • 2
  • j

    John Peña

    03/19/2020, 3:48 PM
    anyone using ktor with datadog? what does your setup look like?
    s
    • 2
    • 3
  • m

    Madhan

    03/20/2020, 6:36 AM
    Hi, I'm Android developer, want to develop Rest api. Can any one explain me how can i host Ktor application in aws server.
    e
    b
    c
    • 4
    • 6
  • c

    Christian Sousa

    03/20/2020, 1:50 PM
    Hello, when I’m doing a get, my code breaks with a 403. I tried to add:
    HttpClient{
            expectSuccess = false
            HttpResponseValidator {
                validateResponse { response ->
                    println("RESP: $response")
                }
                handleResponseException { cause ->
                    println("CAUSE: $cause")
                }}
            }
    But my code doesnt even reach any of those, either the
    validateResponse
    nor the
    handleResponseException
    . With my other api calls, i can see them entering the
    validateResponse
    , but not the one that gives me a 403. Anyone can help?
    👀 1
    e
    • 2
    • 1
  • d

    Darren Bell

    03/20/2020, 5:10 PM
    Hi. In the latest versions of the ktor client HttpResponse has been deprecated. How to I replicate something like
    val myResponse = client.get<HttpResponse>(getHostRequestUrl("/api/getObject"))
    if (myResponse .status != HttpStatusCode.OK) {
        log.error("Issue making service request : Status Code : ${workloadResponse.status}")
    }
    
    val myObject = parseClusterListResponse(myResponse.readText())
    The deprecation error says something like:
    Using 'HttpResponse' is an error. Unbound streaming [HttpResponse] is deprecated. Consider using [HttpStatement] instead
    But I dont think that is appropriate. Am I wrong?
    • 1
    • 1
  • b

    bjonnh

    03/20/2020, 9:42 PM
    Any idea why /index.html isn't served on / using static("/") and returns 404 instead ?
    ✔️ 1
    • 1
    • 4
  • j

    Jamy

    03/21/2020, 6:35 AM
    Hello, is it possible to handle multipart with list of multipart nested in a request ?
    • 1
    • 1
  • m

    Mantas Varnagiris

    03/22/2020, 3:27 PM
    Hi, I'm very new to web development so this is a very noob question. I'm trying to make a page where user can upload a file, then that file is processed and user gets output file for download. I can't find any info on how to achieve that (probably because I don't know what terms to use for search). Here's pseudo code of what I'm trying to do:
    fun Route.handleFile() {
        post("/handleFile") {
            call.respondTextWriter {
                appendln("Writing some output while file is being processed")
                // Handle file that will create another file for user to download
                call.respondFile(outputFile) // I know I cannot do this
            }
        }
    }
    Basically I want to run a long running task and show some text to the user about the progress and then after it finished that output file should be downloaded. Is that even possible to do just within ktor?
    m
    l
    • 3
    • 10
  • c

    carrot

    03/22/2020, 5:50 PM
    Is there an interceptable stage in which I know the HTTP status code of a response?
    • 1
    • 1
  • m

    Marcin Wisniowski

    03/22/2020, 5:56 PM
    Sorry if this is off topic, but I have finished a hobby project with ktor which is a REST API. Now I want to make it publicly available, but I need some monitoring system / see usage graphs etc. Is there something that either integrates with ktor or is just a free API gateway in general? I want some kind of a dashboard where I can see how my ktor API is doing.
    s
    b
    • 3
    • 5
  • b

    Bino

    03/23/2020, 11:48 AM
    Does anyone know, how to publish a custom ktor feature?
    c
    • 2
    • 3
  • g

    gabin

    03/23/2020, 3:57 PM
    hello guys, is ktor 1.3.2 compatible with Kotlin 1.3.71 ? https://github.com/JetBrains/kotlin/releases/tag/v1.3.71
    d
    t
    • 3
    • 2
  • s

    spierce7

    03/23/2020, 5:49 PM
    Is it save to use
    <http://io.ktor.utils.io|io.ktor.utils.io>.errors.IOException
    for all network IO exceptions across platforms?
    l
    • 2
    • 7
  • z

    zero_coding

    03/23/2020, 8:55 PM
    Does Ktor supports Java 13?
    s
    • 2
    • 1
  • l

    LastExceed

    03/24/2020, 10:36 AM
    I have a string property "id" in my json object which i'd like to wrap in an inline class (or data class if necessary), i know i can use
    @JsonValue
    to make the serialization work, but what about the deserialization?
    d
    • 2
    • 2
  • p

    pavlospt

    03/24/2020, 10:53 AM
    Hey friends! 🙂 I have a question regarding
    HttpClient
    usage. If I want to execute an API call when someone “hits” a specific endpoint, do I just need to call
    <http://client.post|client.post>(…)
    inside the route callback, or am I missing something? It is like the call is never executed and cancelled after the specified timeout..! Thanks in advance!
    e
    • 2
    • 15
  • j

    Jeremy Guijt

    03/25/2020, 8:26 AM
    Hi all! I've just started with Kotlin and Ktor and I'm setting up a server with JWT authentication. I want the server to respond with a 401 code and a relevant message when the token is incorrect. For example, if the claim
    userId
    is missing then I would like to have a response saying "Claim 'userId' is missing". I don't think it's currently possible in Ktor and I would like to add it to Ktor. Can any of you offer some insight in whether (a) this is a good feature and (b) how I would go about adding this? The Java library that parses the JWT returns useful information in an exception, but this information is then discarded and an empty UnauthorizedResponse is sent. I think the solution is to add this information to the UnauthorizedResponse as a response body.
    s
    c
    • 3
    • 4
  • j

    Jeremy Guijt

    03/25/2020, 8:28 AM
    This idea is inspired by Django, which also tries to return a helpful message when there is a (client) error.
    • 1
    • 1
  • m

    Martin Tøften

    03/25/2020, 4:21 PM
    Does anyone know when ktor native will work with multithreaded coroutines? I see two github issues that mentions this problem: https://github.com/ktorio/ktor/issues/1543 https://github.com/ktorio/ktor/issues/1538
    r
    • 2
    • 1
  • g

    Gabriel Feo

    03/25/2020, 4:31 PM
    [Resolved] I'm getting a "Not started" error trying to launch a coroutine inside a Ktor call. Anyone knows what this is about?
    Untitled
    c
    • 2
    • 4
  • s

    Sam Garfinkel

    03/25/2020, 6:49 PM
    Are there any types of streaming data types that I can get from the Client that can be safely shared and read from concurrently? I think what I’m looking for is something that will replay the already buffered content and will also properly emit to suspended functions when new content is available.
    e
    • 2
    • 6
  • s

    Shan

    03/25/2020, 11:10 PM
    Is there a way to override a `defaultRequest`s
    host
    ? Doing this is not working:
    val httpClient = HttpClient(Android) {
            defaultRequest {
                contentType(ContentType.Application.Json)
                url {
                    host = currentBuildEnvironment.defaultEndpoint
                    protocol = URLProtocol.HTTPS
                }
            }
        }
    
    //elsewhere..
    fun makeRequest() = <http://httpClient.post|httpClient.post> {
        url {
            encodedPath = "/endpoint"
            host = currentBuildEnvironment.otherEndpoint
        }
        body = //etc
    }
    It's using
    defaultEndpoint
    instead of
    otherEndpoint
    . Am I missing something here?
    o
    • 2
    • 3
  • s

    Sergey Akhapkin

    03/25/2020, 11:29 PM
    Hi folks, I've a strange issue with nested locations in Ktor (1.3.1 and 1.3.2), let assume there are some defined locations
    @KtorExperimentalLocationsAPI
    @Location("/auth")
    object Auth {
        @Location("/phone")
        object ByPhone {
            @Location("/confirm")
            object Confirmation
        }
    }
    and I've a simple test:
    @Test
        fun authLocationsTest() {
            withTestApplication {
                assertEquals("/auth",  application.locations.href(Auth))
                assertEquals("/auth/phone",  application.locations.href(Auth.ByPhone))
                assertEquals("/auth/phone/confirm",  application.locations.href(Auth.ByPhone.Confirmation))
            }
        }
    which is failed with:
    Expected :/auth/phone/confirm
    Actual   :/phone/confirm
    Is that expected behavior and somehow related to https://github.com/ktorio/ktor/issues/1660 or I should file a bug report ?
    • 1
    • 1
Powered by Linen
Title
s

Sergey Akhapkin

03/25/2020, 11:29 PM
Hi folks, I've a strange issue with nested locations in Ktor (1.3.1 and 1.3.2), let assume there are some defined locations
@KtorExperimentalLocationsAPI
@Location("/auth")
object Auth {
    @Location("/phone")
    object ByPhone {
        @Location("/confirm")
        object Confirmation
    }
}
and I've a simple test:
@Test
    fun authLocationsTest() {
        withTestApplication {
            assertEquals("/auth",  application.locations.href(Auth))
            assertEquals("/auth/phone",  application.locations.href(Auth.ByPhone))
            assertEquals("/auth/phone/confirm",  application.locations.href(Auth.ByPhone.Confirmation))
        }
    }
which is failed with:
Expected :/auth/phone/confirm
Actual   :/phone/confirm
Is that expected behavior and somehow related to https://github.com/ktorio/ktor/issues/1660 or I should file a bug report ?
Just to note:
@KtorExperimentalLocationsAPI
@Location("/auth")
object Auth {
    @Location("/phone")
    object ByPhone {
        @Location("/confirm")
        class Confirmation(val byPhone: ByPhone = ByPhone)
    }
}
this code (plus expected changes to test) works as expected. Perhaps it should be reflected better in documentation then.
View count: 4