https://kotlinlang.org logo
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
  • k

    Kweku

    09/20/2021, 2:10 PM
    When using the Auth Bearer feature, calling any type of suspend or coroutine function inside loadTokens causes a crash on Ios, the only error message I get is
    Function doesn't have or inherit @Throws annotation and thus exception isn't propagated from Kotlin to Objective-C/Swift as NSError. It is considered unexpected and unhandled instead. Program will be terminated.
    a
    • 2
    • 2
  • h

    Hien Nguyen

    09/21/2021, 7:58 AM
    io.ktor.util.date.GMTDate
    how to get timestamp of next month with GMTDate 😞 ?
    a
    h
    • 3
    • 6
  • t

    tylerwilson

    09/21/2021, 4:02 PM
    Easy one perhaps: I am using Ktor client side in KMM module, and set query params like so everywhere:
    parameters.apply {
       append("key", value)
       ...
    }
    but all the append calls have the
    This API is internal in ktor and should not be used. It could be removed or changed without notice.
    warning. Is there is a more standard way to define params that will not give this warning?
    a
    • 2
    • 2
  • p

    phil

    09/21/2021, 6:27 PM
    :android-wave: Hi folks! I’m running into a weird situation using ktor’s
    HttpClient
    to send a
    POST
    request to a host in a KMM project. When running the project from an Android app, if I manually set up the Android device on a network by selecting it in the Android system settings, I’m able to connect to the host and send the request using ktor successfully. However if I connect the Android device to the network programmatically via Android’s requestNetwork API, my request with ktor fails immediately with the error
    java.net.ConnectException: Failed to connect to /<host_ip_address>:80
    . Has anyone ever encountered this before, or have any idea as to what might be going on?
    • 1
    • 2
  • j

    jeggy

    09/22/2021, 1:22 PM
    I can see Swagger being mentioned in the ktor docs. But I don't find any information about it except it just pointing over to the OpenApi generator github repo. Is there any simple kotlin example I can just copy and paste to get ktor to generate swagger files?
    b
    a
    • 3
    • 3
  • d

    Dazai

    09/22/2021, 4:45 PM
    hey guys I was hoping to get some feedback on whether i'm using coroutines & ktor sockets properly. It feels weird to be writing a bunch of CoroutineScope(Dispatchers.IO).launch { while(true){ ... do stuff}}} everywhere https://gist.github.com/abueide/f086f6e0cc00c5bd8daf793cc66e0b96
    a
    a
    • 3
    • 5
  • d

    Dazai

    09/22/2021, 4:47 PM
    i think client side is much more messy, not sure how to fix it https://gist.github.com/abueide/948073fe8102b65d0a55c8e0446b163a
    a
    • 2
    • 2
  • b

    Bart

    09/22/2021, 9:45 PM
    Hello All, Im trying to figure out, how i can upload multi records using below example in ktor. I dont see this possiblity using
    call.receive
    Example json:
    {Key:[{Var:value, var:value},{Var:value, var:value}]}
    Any idea how i can handle more that one in single route? Also did its possible to combine two keys in one route?
    a
    • 2
    • 7
  • j

    johnaqel

    09/23/2021, 6:40 AM
    In a Ktor server, is it possible to define a base path globally, so it doesn’t need to be included in the path when declaring a route? E.g. My endpoint is https://example.com/v1/orders but I want to define the route like:
    routing {
        get("/orders") {
    v1 being the base path.
    t
    a
    • 3
    • 2
  • i

    Ivan Brko

    09/23/2021, 5:52 PM
    does anyone know if there is better explanation or good example of jwt tokens auth anywhere? i find the official documentation a bit confusing about this topic, minimal working example would be great
    c
    i
    • 3
    • 6
  • ł

    Łukasz Bednarczyk

    09/24/2021, 6:51 AM
    hi folks 😉 does anyone know when the next version of Ktor could release? I believe that a “request validation” will include in. 😄
    a
    • 2
    • 1
  • l

    Lost Illusion

    09/24/2021, 10:59 PM
    I have a UDP raw socket that I want to transmit data through very rapidly (every x ms). I was wondering if there is any difference between using the
    SendChannel
    provided or whether I should be using
    openWriteChannel
    and sending my data through the returned
    ByteWriteChannel
    instead.
    a
    • 2
    • 1
  • j

    Jan

    09/25/2021, 9:22 PM
    I'm trying to post to a website using MultiPartFormData. But it seems that I'm doing something wrong. Code: (see thread) Here are the docs for this request: https://discord.com/developers/docs/resources/channel#create-message-example-request-bodies-multipartformdata
    a
    • 2
    • 2
  • ł

    Łukasz Bednarczyk

    09/26/2021, 7:14 AM
    One small but IMO important thing to fix: importing of the post method, when we have the location plugin installed. Many people here ask about it
    a
    • 2
    • 2
  • w

    Will Bartlett

    09/27/2021, 12:46 PM
    can anyone comment on the likelihood of this dependabot PR being merged before 1.6.4? https://github.com/ktorio/ktor/pull/2605 theres a fix for kafka metrics that we really want. happy to work around but if it's probably going into 1.6.4 we will just wait.
    a
    e
    • 3
    • 4
  • i

    IsaacMart

    09/29/2021, 3:28 AM
    Hello guys. Am working on a ktor project where am using sessions to store the current userId. I have followed the docs but anytime i want to get my session for userId i am receiving null. I have seen several pple go through this but i haven't found a solution yet. Here is my code and depedencies am using. My Application Class
    fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)
    
    @KtorExperimentalAPI
    @KtorExperimentalLocationsAPI
    @Suppress("unused") // Referenced in application.conf
    fun Application.module() {
        install(Locations) {
        }
    
        install(Sessions) {
            cookie<MySession>("MY_SESSION") {
                cookie.extensions["SameSite"] = "lax"
            }
        }
    
        DatabaseFactory.init()
        val userRepository = UserRepositoryImp()
        val taskerRepository = TaskerRepositoryImp()
        val requestRepository = RequestRepositoryImp()
        val messageRepository = MessageRepositoryImp()
        val reviewRepository = ReviewRepositoryImp()
        val jwtService = JwtService()
        val hashFunction = { s: String -> hash(s) }
    
        install(Authentication) {
            jwt("jwt") {
                verifier(jwtService.verifier)
                realm = "Tasksfy"
                validate {
                    val payload = it.payload
                    val claim = payload.getClaim("id")
                    val claimString = claim.asInt()
                    val user = userRepository.getUser(claimString)
                    user
                }
            }
    
        }
    
    }
    My userRoute class for login.Where am storing the session id
    @KtorExperimentalLocationsAPI
    fun Route.users(db: UserRepository, jwtService: JwtService, hashFunction: (String) -> String) {
    
        post<UserLoginRoute> {
            val signInParameters = call.receive<Parameters>()
            val password =
                signInParameters["password"] ?: return@post call.respond(HttpStatusCode.Unauthorized, "Missing Fields")
            val phoneNumber = signInParameters["phone_number"] ?: return@post call.respond(
                HttpStatusCode.Unauthorized,
                "Missing Fields"
            )
    
            val hash = hashFunction(password)
    
            try {
                val currentUser = db.getUserByPhone(phoneNumber)
                currentUser?.user_id?.let {
                    if (currentUser.password == hash) {
                        call.sessions.set(MySession(it))  //Storing the user id here
                        val token = jwtService.generateToken(currentUser)
    //                    call.respondText(jwtService.generateToken(currentUser))
                        call.respond(
                            ResponseDefault(
                                BaseResponse(true, "Welcome back " + currentUser.first_name, token),
                                currentUser
                            )
                        )
                    } else {
                        call.respond(BaseResponse(false, "Invalid Login details!", ""))
                    }
                }
    
            } catch (e: Throwable) {
                application.log.error("Failed to register user", e)
                call.respond(BaseResponse(false, "Problem retrieving User.Try again later! " + e.message,""))
            }
        }
    My Session Class
    data class MySession(val userId : Int) {
    }
    Here is my depedencies incase there could be problem
    :thread-please: 3
    a
    • 2
    • 11
  • t

    Tiago Nunes

    09/30/2021, 9:54 AM
    Hey everyone, what are HttpRequest attributes? Are they just like “local” data associated with a request instance, or are they actually sent to the network somewhere in the packets?
    a
    • 2
    • 1
  • t

    Tiago Nunes

    09/30/2021, 2:35 PM
    Hey, I’m trying to intercept the response and replace it with the response from a new request, but for some reason, it’s proceeding with io.ktor.client.features.observer.DelegatedResponse…
    🧵 1
    a
    • 2
    • 5
  • h

    Hamza Ahmad

    10/01/2021, 6:08 AM
    Hello, i'm using ktor for http requests and my response come in the below format how i can deserialize and get value from "strDefaultValue" property.
    a
    • 2
    • 1
  • ł

    Łukasz Kłosiński

    10/01/2021, 9:16 AM
    Hi everyone! I am trying to utiliste the built-in proxy (https://ktor.io/docs/proxy.html) but cannot get it to work. I am 100% sure I am either doing something wrong or not doing something I am supposed to. Do you know where I can find a working example?
    a
    • 2
    • 1
  • j

    John O'Reilly

    10/01/2021, 10:10 AM
    Anyone else having issues resolving some of Kotlin/Native artifacts for Ktor 1.6.4 release?
    h
    r
    • 3
    • 5
  • j

    Jose A.

    10/01/2021, 1:15 PM
    Hi! I'm trying to respond to a get query like this:
    call.respondBytesWriter {
        jobOutputRepository.get(id, subId).collect { writeFully("$it\n".toByteArray()) }
    }
    But with curl I'm getting
    curl: (18) transfer closed with outstanding read data remaining
    I tried to add a
    flush()
    but I got the same error. Any ideas?
    a
    • 2
    • 2
  • y

    Yousef

    10/02/2021, 5:08 PM
    Hello, can anyone point me to where I can learn more about localization with ktor? The website I'm building needs to be in 2 languages and I'm not getting much googling kotlin dsl localization or freemarker localization. Mostly android stuff
    b
    • 2
    • 4
  • v

    Viktor Petrovski

    10/04/2021, 12:33 PM
    Hello, What do you use as an alternative for
    cron jobs?
    I want to implement a repetitive task that will execute each ~hour or so to analyse the data created in that hour. Thanks in advance 🙏
    m
    o
    • 3
    • 3
  • s

    Sourabh Rawat

    10/04/2021, 1:57 PM
    Hi, in Ktor-client, how do I set path parameter if I have a url template like
    <https://foo.com/{id}/car/{bar}>
    ? I need to set the values of
    id
    and
    bar
    Thanks in advance.
    m
    c
    • 3
    • 7
  • j

    Jonathan Hollingsworth

    10/04/2021, 7:14 PM
    I’m struggling a little with testing JSON in a post request. It fails within the Ktor tests, but if I send a direct HTTP request in via curl or whatever, it works fine. Totally stumped - any help would be much appreciated.
    l
    a
    • 3
    • 5
  • m

    Miquel Àngel Román

    10/05/2021, 8:33 AM
    Can you use the kotlin native compiler to compile a server-side ktor app? (Assuming no java dependencies are used from the user-code)
    b
    a
    • 3
    • 6
  • j

    Jim

    10/05/2021, 7:11 PM
    Could someone help me find an example of a ktor client that interacts with a versioned rest api?
    t
    a
    • 3
    • 10
  • b

    Berkay

    10/06/2021, 10:56 AM
    Hi there 🙋‍♂️, is there a way to proguard or using dex on ktor backend application?
    d
    j
    • 3
    • 3
  • m

    Mark Schisler

    10/06/2021, 10:27 PM
    Just created a feature request to allow for end-to-end testing with Ktor in Espresso using Idling resources. Right now the path to get there is very jagged, as I tried to explain in the issue. We have worked around the issue for now, but would love official support in a later release. Please up-vote this feature if this would help you out! https://youtrack.jetbrains.com/issue/KTOR-3230
    r
    e
    g
    • 4
    • 5
Powered by Linen
Title
m

Mark Schisler

10/06/2021, 10:27 PM
Just created a feature request to allow for end-to-end testing with Ktor in Espresso using Idling resources. Right now the path to get there is very jagged, as I tried to explain in the issue. We have worked around the issue for now, but would love official support in a later release. Please up-vote this feature if this would help you out! https://youtrack.jetbrains.com/issue/KTOR-3230
r

Rustam Siniukov

10/08/2021, 12:03 PM
@e5l please take a look
e

e5l

10/08/2021, 12:05 PM
Yep, I’m going to add the
coroutineContext
field in the configuration of the test environment in the new testing design
So this should solve the problem.
g

Grégory Lureau

03/14/2022, 2:49 PM
Hello ! Just for visibility on your planning, is it something scheduled for the next release or should I copy/paste the MockEngine in my project and customize it like suggested in the ticket for now? Thanks guys for Ktor btw, I love it!
m

Mark Schisler

03/22/2022, 6:55 PM
thank you all
View count: 7