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

    Simply2vasu

    05/12/2020, 9:47 PM
    hi.. any ideas on how to add rest style pagination headers like
    </test_domain/v2?key=test&per_page=5&page=2>; rel="next",</test_domain/v2?key=test&per_page=5&page=5>; rel="last"
    with ktor
    s
    3 replies · 2 participants
  • g

    gotoOla

    05/13/2020, 9:13 AM
    Does anyone here know about a good way of documenting your APIs with ktor? (something like swagger codegen but it doesn't have to be swagger, anything that produces documentation would be 👍 )
    e
    v
    6 replies · 3 participants
  • j

    Juan Rada

    05/14/2020, 9:27 AM
    guys is it possible in a custom feature in Ktor declares a dependency on another feature?
    e
    2 replies · 2 participants
  • b

    Benedict Pregler

    05/14/2020, 9:49 AM
    Hi, is it normal that the LogLevel.HEADERS only show the headers that are sent but not the headers I receive? (client side/android) My expectation would be the same behaviour as with okhttp, that the headers I receive will also be displayed.
    e
    2 replies · 2 participants
  • r

    rrva

    05/14/2020, 9:50 AM
    please please publish ktor 1.3.2 on maven central
    e
    1 reply · 2 participants
  • r

    rrva

    05/14/2020, 9:51 AM
    jcenter.bintray.com gives me HTTP 502, (it is hosted by jfrog)
    e
    6 replies · 2 participants
  • j

    John O'Reilly

    05/14/2020, 9:53 AM
    When is it hoped to release a version of ktor that works with native-mt version of coroutines?
    👍 3
    e
    d
    7 replies · 3 participants
  • b

    bbaldino

    05/14/2020, 6:42 PM
    Is it possible to serialize handling of a specific route? For example, I have
    user/{userId}
    and want to make sure all requests for a given
    userId
    are handled in the order they were received. I've tried doing this in the route implement, but because there are multiple threads calling it there's still wiggle room as to the order in which they're handled: I know the network is already a variable, but I'm trying to get as close as possible to handling them in the order in which they were received. I looked at doing this in a feature, but even then the request is already dispatched to a worker thread so they've already been parallelized, is there a lower level hook? Or maybe this whole endeavor is misguided?
    s
    t
    14 replies · 3 participants
  • n

    napperley

    05/14/2020, 11:53 PM
    What is the current status on linuxArm32Hfp support for Ktor Client?
    e
    2 replies · 2 participants
  • m

    mp

    05/15/2020, 8:02 PM
    Oh, I should point out another ktor lib I wrote recently. If you have an existing JAX-RS-based app (whether it's just a plain Jersey thing, or Dropwizard, or anything else like that), you can use https://bitbucket.org/marshallpierce/jersey-container-ktor/src/master/ to host your JAX-RS resources inside ktor. This means you're only running 1 server, on 1 port, and you can migrate endpoints from JAX-RS to Ktor one at a time. This is also used in production and serving real traffic.
    b
    1 reply · 2 participants
  • p

    Philipp Mayer

    05/17/2020, 1:24 PM
    How can I expose data from within the Application module scope? Lets say I do the following:
    fun Application.adapter() {
        val topic: SomeObject = SomeObject(environmnet.config.property("something").getString())
    }
    and I want to use the topic Object in a different class (a koin module). I just have the feeling that I'm missing a fundamental concept here.. I just found that github issue, but that doesn't really help me. https://github.com/ktorio/ktor/issues/1448
    1 reply · 1 participant
  • b

    bbaldino

    05/18/2020, 4:42 AM
    Something that I got bit by that I wonder if is intended: when using the
    ktor-client-cio
    client and creating a
    WebSocket
    connection, if the
    HttpTimeout
    feature is installed, it will apply to the
    WebSocket
    connection, even if the connection is actively transmitting messages back and forth. It seems like
    WebSocket
    should be considered an exception to
    HttpTimeout
    ? If not, is it possible to configure
    HttpTimeout
    in a way that it could be applied to some requests (normal ones) but not things like a websocket connection?
    1 reply · 1 participant
  • j

    JoakimForslund

    05/19/2020, 11:33 AM
    Any news of the macosx curl empty body issue https://github.com/ktorio/ktor/issues/1622? Is there anything I could provide to help solving the issue?
    j
    5 replies · 2 participants
  • a

    aleksey.tomin

    05/19/2020, 1:53 PM
    Hello for all, I try to use ktor-client in
    native
    in .kts file
    dependencies {
                    implementation("io.ktor:ktor-client-core:$ktorVersion")
                    implementation("io.ktor:ktor-client-core-macosx64:$ktorVersion")
                    implementation("io.ktor:ktor-client-core-native:$ktorVersion")
    
                    implementation("io.ktor:ktor-client-curl:$ktorVersion")
    
                    implementation("io.ktor:ktor-http-cio:$ktorVersion")
                    implementation("io.ktor:ktor-client-cio:$ktorVersion")
                    implementation("io.ktor:ktor-http-cio-native:$ktorVersion")
                    implementation("io.ktor:ktor-http-cio-macosx64:$ktorVersion")
                }
    It works with CUrl:
    client = HttpClient(io.ktor.client.engine.curl.Curl)
    But doesn’t works with CIO:
    client = HttpClient(io.ktor.client.engine.cio.CIO)
    > Task :compileKotlinMac FAILED
    e: /.../CurlClient.kt: (12, 51): Unresolved reference: cio
    What have I to do?
    👀 1
    e
    9 replies · 2 participants
  • s

    Sabeeh

    05/19/2020, 2:52 PM
    https://stackoverflow.com/q/61894034/5232184
    l
    2 replies · 2 participants
  • j

    JoakimForslund

    05/20/2020, 9:09 AM
    Anyone else noticed that ktor HttpClient on android freezes (and later times out) if you try to send a body a long with a GET request?
    h
    4 replies · 2 participants
  • c

    Carlos Fau

    05/20/2020, 12:20 PM
    Hi, I'm very exited with KTor and I'm using it for several microservices. I created a Feature to integrate prometheus metrics on the http server. It was very easy. Then I created a Feature for the client side, but I got a little confused with the client pipelines and which is the best place to add the interceptor for measure total request time. I want to add to the measure the returned status code from the http response. Any help to understand pipelines and the proper place to inject metrics will be welcome. (edited)
    e
    5 replies · 2 participants
  • c

    Carlos Fau

    05/20/2020, 1:13 PM
    Hi. I wrote an Interceptor to obtain the userId and session Id to be pushed into a ContextElement to be able to get those value in other parts of the app without the need to pass them as parameters all through the business logic. The path is like "/api/users/{userId}/rest-of-path" and the code is similar to this:
    pipeline.intercept(ApplicationCallPipeline.Features) {
                    call.parameters["userId"] --> null
                    proceed()
                }
    The problem is that
    call.parameters["userId"]
    is always null. I guess I'm doing something wrong. Any help?
    2 replies · 1 participant
  • m

    Milan Hruban

    05/23/2020, 6:14 AM
    Hi, I am using ktor server ContentNegotiation features setup like this
    install(ContentNegotiation) {
            json()
        }
    on the client side, I use kotlinx-serialization to serialize a sealed class and post it to server but it doesn't work because the kotlinx-serialization produces different format than ktor-server expects. I thought they are supposed to use the same format. What is the way to make them work together?
    k
    4 replies · 2 participants
  • f

    Fábio Carneiro

    05/23/2020, 6:23 PM
    I was wondering how a proposal for a different approach on the routing configuration would be accepted. Something in the direction of middlewares (similar to expressjs)?! Also something that would return a response object instead of calling a method on a "call" import.
    e
    1 reply · 2 participants
  • j

    Jeff

    05/26/2020, 12:27 PM
    Is it just me or Ktor has very slow startup times? I have a Ktor backend hosted in GCP and uses Cloud SQL (postgres). When the backend has been idle for some time, it requires a new startup which takes almost 1 minute. This breaks the user experience. Why does the app have to start all over again, shoulldn't this happen only once during deployment? I checked and saw that part of the initialization that slows the startup is database work (flyway). Is there a way to speed this up or achieve it asynchronously?
    👀 1
    i
    e
    +2
    12 replies · 5 participants
  • b

    bsimmons

    05/26/2020, 12:55 PM
    Hey all, so I am attempting to make a POST request in a unit test using ktor on iOS (native) and I get this certificate error.
    io.ktor.client.engine.ios.IosHttpRequestException: Exception in http request: Error Domain=NSURLErrorDomain Code=-1202 "The certificate for this server is invalid..."
    Any ideas on how to solve this? (this request works on every other device I've tried.)
    e
    r
    6 replies · 3 participants
  • h

    Hamza

    05/27/2020, 1:36 AM
    how come when I do a OPTIONS request to get whether CORS is enabled or not in the preflight request, it responds with a 403? currently, I have
    install(CORS) {
    		method(<http://HttpMethod.Post|HttpMethod.Post>)
    		allowCredentials = true
    		anyHost()
    	}
    g
    6 replies · 2 participants
  • q

    Quy D X Nguyen

    05/27/2020, 6:05 PM
    Is there a way to split/buffer a ByteReadChannel? My use case is downloading a file from a http URL on GET request and then streaming it to the client as as well as a local file.
    e
    8 replies · 2 participants
  • e

    edenman

    05/27/2020, 8:41 PM
    the ktor Url class seems to accept bogus url strings when you construct with
    Url("bogus")
    (it turns that into http://localhost/bogus)….anybody know of a good kmp way to validate a Url?
    e
    4 replies · 2 participants
  • t

    Thiyagu

    05/28/2020, 2:10 PM
    I was working on migrating to Ktor and in our microservices I need to call external rest webservice to validate my Jwt token. Any idea about how to achieve this with Ktor??
    👍 1
    r
    c
    5 replies · 3 participants
  • a

    Ali

    05/29/2020, 1:36 AM
    I can put it in a pastebin or something for you to look at.
    c
    1 reply · 2 participants
  • a

    aleksey.tomin

    05/29/2020, 5:39 AM
    Hello How I can call ktor-client/curl (1.3.2) post in kotlin-native (1.3.72) with coroutine(1.3.6)? This can produce an error https://github.com/ktorio/ktor/issues/1538
    val result = runBlocking {
        <http://client.post|client.post><String>(url) {
            contentType(ContentType.Application.Json)
            body = json
        }
    }
    1 reply · 1 participant
  • r

    ritesh

    05/29/2020, 12:27 PM
    Hey folks 👋 I’m facing some issues with sending multipart data using Ktor for a multiplatform project. Basically I’m converting the image to
    ByteArray
    and then passing it in the multipart block but server is not accepting it as a multipart request but sees it like a regular post call (and the API is working fine on postman),
    val data: ByteArray = ...
    val urlString: String = ...
    httpClient.request<T>(urlString) {
        method = <http://HttpMethod.Post|HttpMethod.Post>
    	body = MultiPartFormDataContent(
        	formData {
            	append("avatar", data)
        	}
    	)
    }
    Can someone point me to right direction what could be wrong/missing here? Is there some other way to upload an image? Do we have to manually set
    "Content-Type"
    as
    multipart/form-data
    somewhere? 🤔
    e
    4 replies · 2 participants
  • a

    Andrew

    05/30/2020, 2:02 AM
    So the ktor website in its guide for websockets gives the following example:
    install(WebSockets) {
        pingPeriod = Duration.ofSeconds(60) // Disabled (null) by default
        timeout = Duration.ofSeconds(15)
        maxFrameSize = Long.MAX_VALUE // Disabled (max value). The connection will be closed if surpassed this length. 
        masking = false
    }
    However, this doesn't actually work (as far as I can tell), because the receiver of the lambda is the type of the first parameter of
    WebSockets
    , which is
    Unit
    . Anyone know where I went wrong?
    b
    2 replies · 2 participants
Powered by Linen
Title
a

Andrew

05/30/2020, 2:02 AM
So the ktor website in its guide for websockets gives the following example:
install(WebSockets) {
    pingPeriod = Duration.ofSeconds(60) // Disabled (null) by default
    timeout = Duration.ofSeconds(15)
    maxFrameSize = Long.MAX_VALUE // Disabled (max value). The connection will be closed if surpassed this length. 
    masking = false
}
However, this doesn't actually work (as far as I can tell), because the receiver of the lambda is the type of the first parameter of
WebSockets
, which is
Unit
. Anyone know where I went wrong?
b

bbaldino

06/01/2020, 3:52 PM
The
WebSockets
constructor has (some of) those config properties (pingInterval and maxFrameSize)
But agree
WebSockets
doesn't seem to follow the rest of the features there (which have a defined config class)
View count: 2