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

    Antero Duarte

    09/06/2018, 4:24 PM
    Where can I find more information about that?
    e
    • 2
    • 3
  • j

    jw

    09/06/2018, 4:57 PM
    it has an async API. it is not non-blocking internally
    e
    • 2
    • 1
  • s

    samir

    09/07/2018, 7:58 PM
    Hey guys, I am trying to get the body of requests by using
    call.receiveText()
    but it is always empty. I am using version 0.9.4. I saw on the following post on stackoverflow that it was a known issue fixed in v0.9.2. Anyone knows if it is still an issue in the latest version ? https://stackoverflow.com/questions/49895169/ktor-unable-to-receive-post-body-on-server
    б
    • 2
    • 9
  • s

    Semigradsky

    09/09/2018, 10:15 AM
    Hi! Where can I find an example of using the
    MultiPartFormDataContent
    ?
    📝 1
    ✅ 1
    d
    • 2
    • 5
  • n

    Nikky

    09/10/2018, 9:53 AM
    i think this page points users at the wrong artifacts in gradle
    d
    • 2
    • 3
  • n

    Nikky

    09/10/2018, 10:34 AM
    so now.. is there any example of how you can handle url redirects on ktor-client manually? i am dealing with a api returning me incorrectly escaped urls, and with fuel i just disabled redirects and looped until it finally resulted in a file
    d
    • 2
    • 14
  • n

    Nikky

    09/10/2018, 4:54 PM
    https://ktor.io/clients/http-client/features/json-feature.html this page implies kotlinx.serialization is only useable on native with the ktor client ?
    ➕ 1
    e
    r
    • 3
    • 9
  • n

    Nikky

    09/11/2018, 8:06 AM
    so i have been experimenting with kotlinx.serilaizazion for ktor-client . https://gist.github.com/NikkyAI/2e2891ccf67d423c523311f0b43ca57b it seems to be a mess currently, registering classes for read/write mapper seems to make using generics like `List`s impossible this could work if the ktor-client Framework could pass reified types down instead of assuming the Json serializer can handle Any PS: sorry for the many edits, slack keeps cutting out and not actually saving
    e
    d
    +3
    • 6
    • 51
  • n

    Nikky

    09/11/2018, 12:52 PM
    seems like the buildsystem freak out once i try to add a module with
    expectedBy project(':ktor-client:ktor-client-features:ktor-client-json')
    d
    • 2
    • 17
  • j

    Janez Štupar

    09/11/2018, 2:07 PM
    Hi there! I have already tried asking in RX channel, but nobody responded. I am trying to call an Observable pipeline from a Ktor request handler. The problem is that response writer is already closed before Observable produces a result, how do I go about this?
    r
    • 2
    • 4
  • n

    Nikky

    09/11/2018, 5:53 PM
    or maybe typeinfo actually gets me everything i need.. i will experiment
    d
    u
    • 3
    • 8
  • n

    Nikky

    09/11/2018, 9:11 PM
    i could do a
    expect fun serializerOf(typeInfo: TypeInfo): KSerializer<Any>
    to move al lthe jvm specific cruft away.. but i am not sure if that would be considered a good idea
    s
    • 2
    • 6
  • r

    rharter

    09/12/2018, 3:16 AM
    I'm trying to make a high level visual of the architecture of a Ktor Application. Does this look accurate? At this point I'm not going into specifics about the phases, features, and engines, but is it safe to say this is an accurate picture of an entire application?
    o
    d
    • 3
    • 4
  • n

    Nikky

    09/12/2018, 10:00 AM
    general question for PRs on ktor.io .. to keep them up to date, rebase on master/origin or merge ? i do not see many merges in the history so i assume you always rebase, just want to ask and make sure
    e
    • 2
    • 4
  • g

    gildor

    09/12/2018, 10:28 AM
    When should we expect Ktor version with support of 1.3 and stable coroutines? I’m ready to try snapshot version on our project
    d
    e
    • 3
    • 3
  • d

    dave08

    09/13/2018, 12:22 PM
    Is Ktor going to support Coroutines 0.26.0 soon?
    :yes: 1
    e
    e
    • 3
    • 14
  • d

    dave08

    09/16/2018, 3:26 PM
    Right now I have:
    val kodein = Kodein.direct {
         .....
    }
    
    fun Routing.someController(
    		someRepository: SomeRepository
    ) { ... }
    
    fun Application.module() {
          routing {
            someController(kodein.instance())
        }
    }
    But I want to be able to access the
    kodein
    instance inside the
    Application.module()
    in a way that I can replace it in my tests... @Deactivated User?
    ✅ 1
    📝 1
    d
    b
    • 3
    • 6
  • s

    spand

    09/17/2018, 12:34 PM
    Any particular reason
    GsonSerializer.read
    casts deserialized json to
    Any
    ? And not
    Any?
    ?
    b
    • 2
    • 5
  • d

    dave08

    09/17/2018, 7:51 PM
    Isn't that what ContentNegotiation does? For example https://github.com/ktorio/ktor/blob/master/ktor-features/ktor-gson/src/io/ktor/gson/GsonSupport.kt, uses a reader... @enleur
    e
    o
    o
    • 4
    • 15
  • g

    gildor

    09/18/2018, 7:34 AM
    Always better to use SSL
    o
    d
    +2
    • 5
    • 30
  • b

    bdawg.io

    09/18/2018, 7:58 PM
    I wrote a custom authenticator, but the routes seem to be getting called without authentication anyways. Any ideas from the routing and the authentication pipeline snippets?
    Untitled.kt
    d
    • 2
    • 5
  • c

    cy

    09/19/2018, 10:26 AM
    📣 ktor
    0.9.5
    and
    0.9.6-alpha-1-rc13
    has been released. They have the same features but the second is built with Kotlin 1.3 RC. * Added shorthand client functions for HEAD, OPTIONS, PATCH and DELETE methods (#562) * URLBuilder's parser improved (#553, #567) * Improved client's cookie matching and processing * Introduced CallId feature * Added MDC support to CallLogging feature * Fixed setting charset encoding for non-text content types * Added
    respondOutputStream { }
    response function * Migrated to Kotlin 1.2.70 * Split Infrastructure phase into Monitoring and Features phases Migration guide https://ktor.io/quickstart/migration/0.9.5.html
    🎉 14
    d
    • 2
    • 1
  • o

    orangy

    09/19/2018, 10:35 AM
    We’d like feedback on the
    CallId
    feature. If you have a homebrew version of such a feature, or would like to try it, please tell us how it works and if it suites your needs. That’s the last feature before we go towards 1.0 and start fixing only bugs and biggest pain points.
    e
    c
    +3
    • 6
    • 28
  • c

    christophsturm

    09/19/2018, 11:08 AM
    @Deactivated User I’m trying to build the mmo-poc but it say
    Could not find io.ktor.client:ktor-client-redis:0.2.0
    , and indeed there seems to be no version 0.2.0 of that
    d
    • 2
    • 22
  • n

    Nikky

    09/19/2018, 1:02 PM
    is there a reason this is Any ? https://github.com/ktorio/ktor/blob/master/ktor-client/ktor-client-core/src/io/ktor/client/request/HttpRequest.kt#L84 or did nothing in the pipeline require this to me a reified type parameter yet ?
    d
    • 2
    • 6
  • n

    Nikky

    09/19/2018, 1:30 PM
    and something else i tried to do which failed was
    <http://client.post|client.post><List<Users>>(...)
    ✅ 1
    c
    • 2
    • 14
  • m

    mwudka

    09/20/2018, 9:20 PM
    I'd like to build a ktor server that uses the embedded Netty engine, exposes an SSL endpoint, and validates client certificates against a custom CA. Serving over SSL is easy and fun thanks to the magic of ktor, but I'm struggling with validating client certificates. I can see in https://github.com/ktorio/ktor/blob/master/ktor-server/ktor-server-netty/src/io/ktor/server/netty/NettyChannelInitializer.kt#L47 that the
    NettyChannelInitializer
    uses the familiar
    SslContextBuilder
    from Netty. I think that calling
    clientAuth
    and
    trustManager
    on the
    SslContextBuilder
    instance would do what I want. My problem is that I can't see how to pass settings into my engine config to make
    NettyChannelInitializer
    do what I want. Any ideas? Or is this not possible in the current version of ktor, and I should use nginx as a reverse proxy?
    o
    • 2
    • 2
  • o

    oshai

    09/20/2018, 11:33 PM
    I am trying to install application event but it is not running at startup
    d
    • 2
    • 6
  • g

    gildor

    09/21/2018, 7:39 AM
    I tried to find any information about support of kotlinx.serialization on Ktor, I saw that ktor-client-json is there, but it only for http client, is there any issue which I can track to see progress?
    o
    • 2
    • 1
  • a

    Alexander Vasiljev

    09/21/2018, 8:24 AM
    Hello. 1st of all, ktor is super. I've built a sample project with it in no time. I have some difficulties it coupling locations and views (built with html dsl). My views are refactored into separate classes, like this one, for the main template.
    MainTemplate.kt
    d
    o
    • 3
    • 27
Powered by Linen
Title
a

Alexander Vasiljev

09/21/2018, 8:24 AM
Hello. 1st of all, ktor is super. I've built a sample project with it in no time. I have some difficulties it coupling locations and views (built with html dsl). My views are refactored into separate classes, like this one, for the main template.
MainTemplate.kt
d

Deactivated User

09/21/2018, 8:25 AM
what do you mean by coupling locations and views?
a

Alexander Vasiljev

09/21/2018, 8:29 AM
As you see, template references locations https://ktor.io/servers/features/locations.html they are defined elsewhere in the project:
@Location("/products")
class Products
@Location("/platforms")
class Platforms
@Location("/deviceModels")
class DeviceModels
so instead of using error-prone string literals inside template, like
a(href = "/products") { +"Products" }
one is able to
a(href = href(Products())) { +"Products" }
-- the feature is great!
The problem is to resolve the location (
href(Products())
) inside the template. Corresponding function
href
is available only in Routing context. For now I am using the trick:
var href: (Any) -> String = { "" }

fun Routing.commonRoutes() {

    href = fun(location: Any): String { return application.locations.href(location) }
  // etc.
and wonder if more elegant solution might exist?
Or maybe ktor framework will add some global function to resolve location even out of Routing context?
d

Deactivated User

09/21/2018, 8:57 AM
Aha, let me check
I’m checking why href depends on the Routing/ApplicationCall context. Still I guess you can create a
Template
subclass with a
call: ApplicationCall
, and make a href method or extension method for that class that calls the right method with the right context
I believe that the context is used to cache the information per type
a

Alexander Vasiljev

09/21/2018, 10:21 AM
Your suggestion is correct, yet the code would become little too verbose in my scenario:
fun Routing.productRoutes() {
    get<Products> { _ ->
        call.respondHtmlTemplate(
                ListTemplate(
                        title = "All products",
                        tableModel = allProductTableModel(),
                        href = fun(location: Any) = this@productRoutes.application.locations.href(location)
                )
        ) {}
    }
}
same code for every get or post
instead of
fun Routing.productRoutes() {
    get<Products> { _ ->
        call.respondHtmlTemplate(
                ListTemplate(title = "All products", tableModel = allProductTableModel())
        ) {}
    }
}
and pithiness is what we love kotlin (and ktor) for
o

orangy

09/21/2018, 10:34 AM
I admit
Locations
is a feature that needs much more attention, but unfortunately right now we don’t have enough resource. It’s not about coding, more about designing it better.
In general, we don’t really allow static context, it doesn’t work well with multiple servers in the single process, doesn’t work great with multithreading, etc. So you will still have to pass some context into a template.
All you need is
Location
feature instance, so it shouldn’t be too hard?
If you’re fine with some statics, you can have a global lateinit variable that you initialize with an
Application
instance and use it everywhere.
But I would suggest against it 🙂
a

Alexander Vasiljev

09/21/2018, 10:40 AM
Current solution is nothing more then hack, that would break in multithread environment, I agree completely here.
o

orangy

09/21/2018, 10:41 AM
Static application (or Location instance) won’t break in multithreaded environment, given you have only one app in a JVM and you initialize it once and never change.
d

Deactivated User

09/21/2018, 10:43 AM
you can also make your html builder suspend, and use the
coroutineContext
as a dependency container 🤨, like a scala implicit. Though I wouldn’t do that either the main problem with globals (in addition to multithreading issues) is testing or multiple applications, you normally want to start things from scratch. Even when in control at the beginning, it is a bad practice in general
a

Alexander Vasiljev

09/21/2018, 10:43 AM
It’s not about coding, more about designing it better.
So I provided you with feedback from a real world application. Anyway, thank you for a wonderful framework.
o

orangy

09/21/2018, 10:47 AM
Thanks for feedback 🙂 It would be awesome if you could post an issue to GitHub so we have it handy when we’ll work on the design.
@Deactivated User coroutine context is a nice idea indeed! However it would require changes to kotlinx.html I believe
a

Alexander Vasiljev

09/21/2018, 10:49 AM
or Location instance
I do not see that Location instance would be of any use though. E.g. there are actually @Location("/products") class Products { @Location("/{id}") class Item(val id: Int) } and later:
private fun ProductModel.asRowModel(): RowModel {
    return RowModel(listOf(RefCell(id) { href(Products.Item(id)) }, PlainCell(name)))
}
It is possible to embed links into list view. Each to corresponding item:
href(Products.Item(id))
for every item in the list
o

orangy

09/21/2018, 10:51 AM
I mean
Locations
feature instance, like
application.locations
a

Alexander Vasiljev

09/21/2018, 10:51 AM
Ah, I see
d

Deactivated User

09/21/2018, 10:54 AM
@orangy I thought that the DSL was inline already. But just checked and it is not the case, so yeah, it wouldn’t work directly. You would have to get the links before the DSL.
a

Alexander Vasiljev

09/21/2018, 11:31 AM
@orangy here is an issue: https://github.com/ktorio/ktor/issues/597
👍 1
View count: 2