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

    Marko Kunic

    01/11/2022, 4:58 PM
    does anyone have an example of how would I load an
    .env
    variables into ktor before starting local env or running tests?
    👍 1
    b
    t
    +2
    • 5
    • 4
  • s

    snowe

    01/12/2022, 5:11 AM
    why am I unable to resolve
    JsonFeature
    even if I have
    ktor-client-json
    as a dependency? It was working at some point and now I cannot get it to work, even if I create a new project using the ktor intellij creator. Maven is just completely unable to resolve the
    .json.
    package.
    a
    • 2
    • 7
  • f

    Florentin Simion

    01/12/2022, 2:15 PM
    Hello! I am using Ktor for some time now and I could say that I became pretty familiar, but there is still a thing that puzzles me 😅 What problem addresses / solves
    SuspendFunctionGun
    in respect to the naive implementation of
    DebugPipelineExecutor
    ? @e5l maybe you can help me understand, as you are one of the main committers, Thank you!
    e
    • 2
    • 8
  • c

    Chris C

    01/12/2022, 3:13 PM
    Hi, I’m trying to build my project which depends on
    io.ktor:ktor-client-core:2.0.0-beta-1
    and i’m running into this error:
    Uncaught Kotlin exception: kotlin.IllegalArgumentException: Failed to open iconv for charset ISO-8859-1 with error code 22
        at kfun:kotlin.Throwable#<init>(kotlin.String?){} (0x44cb61)
        at kfun:kotlin.Exception#<init>(kotlin.String?){} (0x4464bd)
        at kfun:kotlin.RuntimeException#<init>(kotlin.String?){} (0x44665d)
        at kfun:kotlin.IllegalArgumentException#<init>(kotlin.String?){} (0x44697d)
        at kfun:io.ktor.utils.io.charsets.checkErrors#internal (0x729962)
        at kfun:io.ktor.utils.io.charsets.CharsetImpl.<init>#internal (0x7289cd)
        at kfun:io.ktor.utils.io.charsets.Charsets#<init>(){} (0x72f4b3)
        at InitSingletonStrict (0x61a64d)
        at  (0x85bffc)
        at Kotlin_initRuntimeIfNeeded (0x638c06)
        at Init_and_run_start (0x436296)
        at __libc_start_main (0x7f82ef801c8d)
        at  (0x41d767)
        at  ((nil))
    This is running on our Alpine Linux build server which has iconv available
    echo 'foo' | iconv -f ISO-8859-1 -t ASCII
    foo
    Any ideas what’s going on here?
    a
    • 2
    • 1
  • z

    Zhiqiang Bian

    01/12/2022, 4:36 PM
    Hi, I have a question on Ktor-Client 1.6.7 Bearer token. Is it possible to customise the condition of calling
    refreshTokens
    function? For example, without the
    WWW-Authenticate
    header? https://ktor.io/docs/auth.html#bearer
    3. Specify how to obtain a new token if the old one is invalid using refreshTokens. Note that this block will be called after receiving a 401 (Unauthorized) response with the WWW-Authenticate header.
    d
    p
    • 3
    • 3
  • j

    Jim

    01/13/2022, 11:04 PM
    Has anyone here done ssl cert ignoring for js? I'd like to run e2e tests in my kotest kotlin js suite that uses a ktor js client to talk to some server with self signed certs 🤔
    a
    • 2
    • 2
  • s

    spierce7

    01/14/2022, 3:55 AM
    What would be the best way to decode gzipped requests in a ktor server?
    a
    • 2
    • 2
  • h

    Hassaan

    01/14/2022, 6:12 AM
    Is there any advantage using nodejs over ktor for backend or every possible thing could be done using just ktor
    :ktor: 1
    a
    r
    • 3
    • 5
  • a

    Alexander Suraphel

    01/14/2022, 10:59 AM
    I started a new ktor project and i’m adding sqldelight dependency but I’m getting the error:
    Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
    The project is just a single module build ( no top level buiild.gradle.kts file) How do i fix this?
    b
    • 2
    • 8
  • a

    Alexander Suraphel

    01/14/2022, 2:09 PM
    I’m trying to respond with JSON while following with these dependencies on my project . However I cannot import
    ContentNegotiation
    . Am I missing a dependency?
    a
    • 2
    • 20
  • m

    martmists

    01/14/2022, 3:20 PM
    Is there a library for bucket-based per-client ratelimiting? I've only found ones that have a global configuration rather than allowing specifying it per bucket (if it even had buckets)
    r
    • 2
    • 2
  • s

    spierce7

    01/15/2022, 1:46 AM
    If I want to catch all my exceptions and log them to bugsnag, or Datadog, where is the best place to do that? I was considering the
    StatusPages
    plugin, using the
    Throwable
    catch all.
    install(StatusPages) {
                exception<Throwable> {
                    call.respond(HttpStatusCode.InternalServerError)
                }
            }
    r
    r
    a
    • 4
    • 7
  • d

    dimitar_

    01/15/2022, 12:03 PM
    Hi, I’m trying out Ktor and want to configure some routes with
    Locations
    I have a problem configuring a simple
    POST
    endpoint. I have the following code:
    @Location("/v1/login")
    class Login
    
    post<Login> {
     ...
    }
    But I get 404s. If I change it to
    get<Login> {…}
    everything is ok. Can’t seem to find any examples using
    post
    and
    Locations
    d
    a
    • 3
    • 8
  • a

    Alexander Suraphel

    01/15/2022, 2:11 PM
    I just created a project with Ktor but my changes are not auto reloading unless I rerun the app on IntelliJ. Is there auto-reload out of the box?
    b
    r
    • 3
    • 6
  • a

    Akram Bensalem

    01/16/2022, 10:02 AM
    I want to Upload an image from Android to server as Binary form. the postman code is:
    curl --location -g --request POST '<https://svform.herokuapp.com/createUser/{userName}/{mobileNumber}>' \
    --form 'profileImage=@"/Users/akram/Documents/14_07_2020-hbtu_kanpur_20509722.jpg"'
    So I write a code like this:
    @OptIn(InternalAPI::class)
    suspend fun creatUser(
        context : Context,
        userName: String,
        mobileNumber:String,
        image: Uri,
    ) = client
        .submitFormWithBinaryData<MemberEntity>(
            url = "$POST_NEW_USER/$userName/$mobileNumber",
            formData = formData {
                append(
                    key = "profileImage",
                    value = getBinaryFile(context = context, contentUri = image)!!
                )
            },
    
                ){
    
            onUpload { bytesSentTotal, contentLength ->
                println("Sent $bytesSentTotal bytes from $contentLength")
            }
       }
    I got an error of type :
    Serializer for class 'BinaryItem' is not found.
    When I add the ContentType, I got another error
    Header(s) [Content-Type] are controlled by the engine and cannot be set explicitly
    ..... Please any help ?
    a
    • 2
    • 4
  • s

    Sergei

    01/16/2022, 10:53 AM
    Hi dear community, have been messing around with Ktor and HOCON configs, I found that you can feed different application config as an argument, but is there something similar to spring boot's "active profiles"? Where you can provide multiple configs, like some main config that describes everything, and some smaller dev/other config after main one, that overrides only few things it has, without a need to duplicate all the other configuration properties between multiple configs.
    a
    s
    • 3
    • 2
  • a

    Alexander Suraphel

    01/16/2022, 2:22 PM
    What is the purpose of Ktor-cli and how do i use it?
    a
    • 2
    • 2
  • a

    Alexander Suraphel

    01/16/2022, 3:13 PM
    Is there any effort by JetBrains to support graphql server out of the box with Ktor? Interested in hosting a server on iOS device.
    👀 1
    o
    • 2
    • 2
  • s

    Stefan Oltmann

    01/17/2022, 2:03 PM
    I can't figure out how I can call Dropbox API using Ktor 1. I need to post JSON data to this endpoint: https://www.dropbox.com/developers/documentation/http/documentation#files-list_folder This does not work:
    var delta: DropboxDelta = post("$DROPBOX_API_URL/files/list_folder") {
        contentType(ContentType.Application.Json)
        body = Parameters.build {
            append("path", "/")
            append("recursive", "true")
            append("include_non_downloadable_files", "false")
        }.formUrlEncode()
    }
    Client request(https://api.dropboxapi.com/2/files/list_folder) invalid: 400 Bad Request. Text: "Error in call to API function "files/list_folder": request body: expected object, got string" For OAuth I can use this construct:
    return tokenClient.submitForm(
        url = tokenUrl,
        formParameters = Parameters.build {
            append("grant_type", "authorization_code")
            append("code", authorizationCode)
            append("client_id", clientId)
        }
    )
    But that does not work with list_folder Can someone share an example how to do this?
    ✅ 2
    • 1
    • 1
  • h

    Hamza Maqsood

    01/17/2022, 2:29 PM
    hello channel, a quick question about websockets in ktor for example in node js(socket.io), we can do something like this: socket.broadcast.to(socket).emit('event_name', JSON.stringify(data)) the event_name can be used to differentiate between event types on client side, how to do something like this in ktor? all I can see in ktor examples is that you send message as: socket.send(Frame(data)) Is there a neat way to send the event type along with the data?
    a
    • 2
    • 12
  • m

    mp

    01/17/2022, 3:12 PM
    hi there guys does ktor has the way (mode\interceptor arguments for configuration) how to join all logs related to request\response to one log record? or should I make it by myself as my own interceptor? not very convenient to log all(method, header, body) info separately in my case
    a
    r
    a
    • 4
    • 26
  • a

    Alexander Suraphel

    01/18/2022, 12:46 PM
    How do i turn on development mode if I don’t have
    application.conf
    . Can I do it inside the
    embeddedServer
    call?
    a
    • 2
    • 2
  • m

    martmists

    01/19/2022, 8:58 AM
    How do I clear the session cookie from the server-side?
    a
    • 2
    • 1
  • m

    martmists

    01/19/2022, 2:28 PM
    Is there a way to easily make RSS feeds with ktor or will I have to make one myself?
    a
    • 2
    • 1
  • c

    Claude Brisson

    01/19/2022, 5:56 PM
    Hi all. With 2.0-eap (2.0.0-eap-278), StatusPages does not seem to catch exceptions occurring during HTML DSL rendering. I saw a git commit fixing the same issue for freemarker, KTOR-343 ( git diff 18222b4e8~ 18222b4e8 ), which I don't fully understand, lacking some knowledge about the 2.0 refactoring; I was wondering if it was the same kind of problem. Also, would the Velocity plugin also be affected?
    a
    • 2
    • 7
  • a

    Alexander Suraphel

    01/20/2022, 10:38 AM
    I’m reading how to serve static content with ktor. In the snippet below:
    routing {
    static("assets") {
    files("css")
    files("js")
    }
    }
    Does
    files("css")
    look for the folder
    css
    and/or files with the extension
    .css
    ?
    b
    • 2
    • 4
  • a

    Alexander Suraphel

    01/20/2022, 10:40 AM
    What is the difference between
    files
    and resources ? StackOverflow question
    ✔️ 1
    b
    a
    • 3
    • 19
  • с

    Стефан Јовановић

    01/21/2022, 2:46 PM
    Hey people, anyone can help me with Google JWT? So I'm building an Android app, and also there I'm authenticating my users with Google. They authenticate successfully and I get their JWT as a response. Now since I'm also using Ktor for my back-end (where I'm planning to store their profile information), I also need to verify their Google JWT token, before I can store/save their information on my server.. What's the best way to verify my users Google JWT on Ktor server? Is there any API available? 🤔
    s
    l
    • 3
    • 2
  • s

    spierce7

    01/22/2022, 7:12 AM
    Is there a way to create a custom
    CoroutineContext
    that’s used for all requests? I swear there was a way to do this that I read a while ago, but I can’t find it in the documentation. If I use an Authentication provider, currently that authentication information is only stored inside the
    call
    . I’d like to create a custom
    CoroutineContext
    for each request, so that anywhere in the server that I’m in a
    suspend
    function, I can get the userId, instead of having to pass it through to every method call in my server.
    r
    • 2
    • 2
  • b

    brabo-hi

    01/25/2022, 1:37 AM
    Hi all, it looks like you can’t cash
    HttpClient
    with
    CIO
    when using
    WebSockets
    . But it looks working fine with Http ? Here is the error i am getting Kotlin multiplatform: JobCancellationException: Parent job is Completed
    a
    • 2
    • 3
Powered by Linen
Title
b

brabo-hi

01/25/2022, 1:37 AM
Hi all, it looks like you can’t cash
HttpClient
with
CIO
when using
WebSockets
. But it looks working fine with Http ? Here is the error i am getting Kotlin multiplatform: JobCancellationException: Parent job is Completed
a

Aleksei Tirman [JB]

01/25/2022, 8:39 AM
Could you please share a code snippet to reproduce your problem?
b

brabo-hi

01/25/2022, 5:31 PM
class MyService {
    private val client= HttpClient {
       install(WebSockets)
    }
    fun openSocket() {}
    fun closeSocket(code: Int, reason: String) {}
    fun sendMessage(msg:String) {}
}
The issue was when using the same instance of
MyService
val myService = MyService()
myService.sendMessage();
Here i want to reuse the same
myService
instead of creating a new instance each time i want to start a new connection
View count: 1