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
server
  • р

    Ролан

    05/07/2021, 5:26 PM
    Hi, could someone recommend me something equivalent to akka-streams native to Kotlin, I need something lightweight that can handle backpressure and publish/subscribe patterns? thanks
    j
    n
    • 3
    • 6
  • g

    Geert

    05/14/2021, 12:09 PM
    I want to start server development using Kotlin. So i thought I wanted to use Ktor, but IntelliJ mentions its Obsolete? Am I missing something?
    j
    n
    j
    • 4
    • 6
  • a

    Abdulazeez Olaitan Gbindinninuola

    05/18/2021, 10:39 AM
    Any course to start learning server side Kotlin ...
    v
    • 2
    • 1
  • b

    Byron Katz

    05/20/2021, 10:12 PM
    For fun and exercise, to practice pair programming and TDD, our team has built a web application from scratch in Kotlin, including all necessary parts (web server, database, framework), all in one. The only production dependency is the standard library. https://github.com/7ep/r3z . Perhaps you will find it useful. Let me know.
    👏 3
    k
    • 2
    • 1
  • a

    asavio

    05/21/2021, 12:37 PM
    My new team does a Kotlin micro-service with Vert.x (I just came into the Kotlin world from Java, loving it so far!) However, I couldn’t find any books on Vert.x with Kotlin (with coroutines). There are so many Vert.x books with Java. If anyone could let me know of a book, it would be super helpful. Thanks in advance!
    d
    a
    • 3
    • 5
  • v

    Vasily Scherbakov

    05/23/2021, 12:28 PM
    Hi, guys! Recently started to develop full stack application using kotlin with ktor as backend. And now i have a problem with cors policy
    Access to fetch at '<http://127.0.0.1:8080/api/run?userId=root&profile=test>' from origin '<http://localhost:3000>' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled
    As i understand, i should add origin to list of allowed origins in my backend app, i do this that way
    install(CORS){
            method(HttpMethod.Get)
            method(<http://HttpMethod.Post|HttpMethod.Post>, )
            method(HttpMethod.Delete)
            anyHost()
            host("localhost")
        }
    But this dont work. This is headers of response from js clinet
    'Origin': '<http://localhost:3000>',
                    'Content-Type': 'application/json',
                    'Accept': 'application/json',
                    'Access-Control-Request-Headers': 'Content-Type, Authorization'
    Can anyone help me please?
    a
    a
    • 3
    • 2
  • d

    Darren Lambert

    05/24/2021, 10:04 PM
    Hi guys, i use kx.ser and i'm stuck with my post request, the terminal say to me :
    2021-05-24 17:50:38.841 [eventLoopGroupProxy-4-1] ERROR ktor.application - Unhandled: POST - /Music/Add
    io.ktor.features.CannotTransformContentToTypeException: Cannot transform this request's content to Musics
    What i have do wrong in my code ? 😒miling_face_with_tear: (I have do many research and soluce but he doesn't work)
    post("/Add") {
            val post = call.receive<Musics>()
            aMusicDAO.addMusic(post)
            call.respondText("OK OK",ContentType.Text.Plain)
    }
    
    @Serializable
    data class Musics(
        val tag:Int? =null,
        @JsonInclude(value=JsonInclude.Include.NON_NULL)
        val title:String?="",
        val artist:String?="",
        val duration: String?="",
        val tagU:Int? =null
    )
    
     override fun addMusic(music: Musics){
            transaction {
                    Music.insert{
                        it[title]= music.title ?:""
                        it[artist]=music.artist?:""
                        it[duration]=music.duration?:""
                        it[tagU]=music.tagU?:0
                    }
                }
        }
    a
    c
    • 3
    • 3
  • e

    ESchouten

    05/26/2021, 9:58 PM
    Hi! I created a backend based on the Clean Architecture principles. Feedback would be very much appreciated! The application is separated into three modules: Domain, Usecases and Adapters • Domain module contains all entities, it's validation and repository interfaces • Usecases module performs actions on the domain entities and repositories and does authorization The domain and usecase modules do not have any external dependencies. • Adapter layer: each adapter is implemented as a standalone module, lowering dependence on specific frameworks and libraries and making them interchangable. The server module consumes all adapters (e.g. databases, (graphql) endpoints, authentication logic) GraphQL endpoints are auto-generated from the Usecases Used technologies: Ktor, JWT, Exposed, Flyway, KGraphQL/GraphQL generated endpoints. https://github.com/ESchouten/CleanArchitecture
    👏 3
    e
    j
    d
    • 4
    • 9
  • s

    Slackbot

    05/30/2021, 11:32 AM
    This message was deleted.
    a
    • 2
    • 1
  • n

    ninad thakare

    05/30/2021, 1:25 PM
    I am interested in kotlin for backend and server driven UI. Any idea how to do it?
    m
    b
    +2
    • 5
    • 9
  • d

    Debanshu Datta

    05/30/2021, 5:12 PM
    I am try to set up a android client with ktor for websocket? Any idea on that?
    a
    z
    • 3
    • 3
  • j

    João Rodrigues

    06/01/2021, 9:55 AM
    Hey 👋 I'm developing a backend with Ktor, loving the framework so far! In some cases, I'll have to handle several (possibly large) responses from another backend, process them and forward them to my client. For now this is all rest, no web sockets. Is there anyway in Ktor to have a constant flow of responses to the client? Something like Spring WebFlux, I'd like to have a reactive flux of responses in Ktor. Have you ever implemented such thing with Ktor? Is it even possible as the framework stands today? Did you have success with any other framework? Thanks in advance 🙏
    n
    e
    • 3
    • 4
  • c

    cuongtd

    06/05/2021, 5:20 AM
    hi everyone, this is my first using ktor, I just cloned this repo https://github.com/ktorio/ktor-http-api-sample from ktor’s docs. after running the project, I see this in terminal window: Application - Responding at http://0.0.0.0:8080, but when I try to access it from browser, it gives me This 127.0.0.1 page can’t be found. does anyone know why, did I miss anything? I tried to use different port and host but still the same result
    d
    • 2
    • 4
  • j

    jmfayard

    06/07/2021, 5:04 PM
    Hello friends, I have a client with a legacy Java backend project (Spring + Java 5). He is "open to Kotlin" but needs to be convinced. How would you make succintly the case for Kotlin on a server application?
    b
    e
    +5
    • 8
    • 12
  • s

    Slackbot

    06/10/2021, 2:29 AM
    This message was deleted.
    a
    • 2
    • 1
  • s

    Sergey

    06/10/2021, 7:17 PM
    Hi there, I’m using ktor for communication between backend services (kinda rpc) and wonder is there h2c support? I obviously don’t need any tls facilities. My setup is ktor 1.6.0 on netty transport. So far I have found this 9 months old unanswered SO question.
    a
    • 2
    • 1
  • m

    Michael Grigoryan

    06/11/2021, 6:31 PM
    Hi! Can someone please help me to solve this question? https://discuss.gradle.org/t/kotlin-dsl-jar-compile-error-exception-in-thread-main-java-lang-noclassdeffounderror/40210/1
    ✅ 1
    d
    a
    e
    • 4
    • 32
  • h

    Hafs

    06/12/2021, 9:15 PM
    Hello Guys I'm trying to deploy a sample ktor api project from intellijIdea, but not working can anybody help?
    a
    • 2
    • 3
  • v

    Voytech

    06/13/2021, 12:14 PM
    Hello there - Do You think is it idiomatic to use extension functions on data transfer objects in order to map to some other representation? I have doubts - as name suggests ‚extension function’ are for extending functionality of a class which already does something, while DTO should carry only data and no functions. On the other hand - extension function does not add methods to the extended object but are resolved statically - so DTO in its binary representation is still plain. It only lexically looks like you are messing with DTO. I would like to know your opinions.
    d
    a
    +3
    • 6
    • 8
  • p

    Pavel Petkevich

    06/14/2021, 5:01 PM
    Hello to all 😄 I have a question regarding of using Redis with Ktor Server Side Application, have some of you already tried: io.ktor.clients:ktor-client-redis ? -> Or you can suggest me something different to use? Thank you in advance for any answer 😄
    c
    b
    j
    • 4
    • 5
  • l

    Lena Stepanova

    06/16/2021, 9:45 AM
    Hello everyone! An Android developer with very little backend experience, I am interested to learn more of it. Kotlin seems to be getting more popular for backend development and to pair very well with KMP projects. Therefore I have several questions, mostly about how and where to start: 1. Is it reasonable/worth it to start learning Backend development with Kotlin? Or should I rather choose Java frameworks as they are more mature? Having lots to do with KMM not sure how happy I'll be learning backend from start in "experimental" mode 2. Which framework is good to choose for a beginner? Kotlin Spring probably benefits from the maturity of Java Spring, whereas I have seen and heard more about Ktor implementations. Also using Ktor in the client side in KMM may be a good addition to learning backend with Ktor. Or would you recommend a completely different option? 3. Any tutorials/starter projects/guides/learning kits you can recommend? 4. Speaking of completely different options, may be there is something different from Kotlin options you'd recommend? I've heard good things about Go backend developments - good for beginners. This being a kotlinglang slack, I totally understand the answers may be biased, still will appreciate any opinion and advise!
    h
    h
    +5
    • 8
    • 11
  • h

    Husam

    06/18/2021, 12:22 PM
    #code-coverage do this survey! https://twitter.com/kotlin/status/1405526653330104333?s=19
    c
    • 2
    • 1
  • c

    christophsturm

    06/21/2021, 9:33 AM
    announcing Restaurant, a kotlin web server api with focus on testability and coroutine support: https://github.com/christophsturm/restaurant
    ❤️ 2
    s
    s
    • 3
    • 9
  • r

    reperion.kim

    06/22/2021, 1:02 AM
    HI there. I'm working on spring-boot-kotlin and trying to replace apache-http/okhttp to CIO. Can I get a performance comparison?
    g
    d
    v
    • 4
    • 8
  • c

    Cisino da Silva Gomes Junior

    06/25/2021, 6:19 PM
    Hey all! Can someone share with me some experience creating a GraphQL server using kotlin?
    m
    a
    • 3
    • 4
  • i

    iamraghavawasthi

    06/28/2021, 7:17 PM
    Hey folks. I'm working on a realtime Chat System. I was Using Firebase previously. Now I need to switch to Custom backend. Can someone share his experience on NodeJs + Socket.io vs Ktor
    r
    a
    • 3
    • 4
  • l

    Luiz Aguiar

    06/30/2021, 10:15 PM
    Hey all, Can someone recommended a kotlin based state-machine library? Found one from Tinder but the license is restrictive, others are mostly old Java based.
    e
    k
    +5
    • 8
    • 11
  • j

    jmfayard

    07/02/2021, 8:57 AM
    Hello friends: a non-technical question. I want to work with Kotlin on the server-side, so I'm trying to figure out which companies use Kotlin there, but I'm flooded with offers for Kotlin. on Android. Any idea how to proceed? I'm in Europe
    🇫🇷 2
    e
    t
    +4
    • 7
    • 9
  • р

    Ролан

    07/06/2021, 11:44 AM
    @antonarhipov maybe that question has been asked many times already so sorry about that - is there a Kotlin Multi-platform version of this wonderful tutorial with KotlinJS: https://github.com/kotlin-hands-on/kotlin-spring-chat  Thanks in advance!
    a
    d
    • 3
    • 5
  • a

    Amitav Khandelwal

    07/08/2021, 9:19 AM
    Hi guys! I’ve been working on spring boot with kotlin recently. I have a question around architecting a complex stepwise process - might be more general software than kotlin/spring. I’ve got a endpoint for placing an ecommerce order that has several steps involved (say 1, 2, 3, 4), and a lot of params in the request as well. Each one of these steps ends up transforming the initial request in a way that gives a complex output as a result - which I’ve modelled into their own output
    data class
    es, like
    Step1Output
    , which becomes the input for step 2, and so on. I’ve managed to make the step functions are pure functions this way, which I believe is a best practice. My problem now is that in case I need to introduce anything new in the output that requires another piece of data from the input, I need to modify all my
    StepXOutput
    classes and keep passing on the data between them. This obviously makes doing any changes slow and painful. Any ideas on design patterns that can help with this? Or is there some well-architected, complex project that I can look at for reference? Thanks!
    n
    k
    +4
    • 7
    • 11
Powered by Linen
Title
a

Amitav Khandelwal

07/08/2021, 9:19 AM
Hi guys! I’ve been working on spring boot with kotlin recently. I have a question around architecting a complex stepwise process - might be more general software than kotlin/spring. I’ve got a endpoint for placing an ecommerce order that has several steps involved (say 1, 2, 3, 4), and a lot of params in the request as well. Each one of these steps ends up transforming the initial request in a way that gives a complex output as a result - which I’ve modelled into their own output
data class
es, like
Step1Output
, which becomes the input for step 2, and so on. I’ve managed to make the step functions are pure functions this way, which I believe is a best practice. My problem now is that in case I need to introduce anything new in the output that requires another piece of data from the input, I need to modify all my
StepXOutput
classes and keep passing on the data between them. This obviously makes doing any changes slow and painful. Any ideas on design patterns that can help with this? Or is there some well-architected, complex project that I can look at for reference? Thanks!
n

nfrankel

07/08/2021, 9:23 AM
might be more general software than kotlin/spring.
it is general design hence... :not-kotlin:
➕ 2
a

Amitav Khandelwal

07/08/2021, 9:25 AM
I was checking here if there was something specific to kotlin or spring that could help with this 🤷
🚫 1
k

kqr

07/08/2021, 10:44 AM
isn't your problem usage of data classes?
a

Amitav Khandelwal

07/08/2021, 10:46 AM
Is there some better data structure that I could use in this case?
k

kqr

07/08/2021, 12:05 PM
well I don't fully understand your usecase, but it looks like inheritance could help you
q

Quincy

07/08/2021, 12:56 PM
@Amitav Khandelwal, how often are you expecting the outputs to change? If it's not often then it may not be worth changing anything because the pain may be too infrequent. Otherwise, if you feel you need to make a change then maybe strong typing is what is getting in your way. What if instead of using
data class Step1Output(...)
you just passed around a
Map<String, Any>
? You still need to deal with setting and accessing any new keys you put into the map later on, but nothing about how you transport the data needs to change. It's just a map. If you have a need for a nested map, i.e., your existing data classes aren't just full of primitives, then you could wrap the map in a class the lets you more easily access the nested values. For example:
outputMap.getValue("/firstKey/secondKey/thirdKey")
instead of
outputMap.get("firstKey")?.get("secondKey")?.get("thirdKey")
In projects I work on we've had a lot of success in the past using classes that delegate to a map as well.
data class Foo(map: Map<String, Any>): Map<String, Any> by map
You can add functions to
Foo
to make certain patterns of data access easier, but you still get to treat it like a map. You can even add functions to set and retrieve values in a type safe way if that's important to you.
n

nkiesel

07/08/2021, 4:15 PM
Looks like your real problem is that you connected the data structures to the indices of the steps. Therefore, inserting into the list requires renumbering of all following steps. I would instead use names for the steps like
AddressVerificationInput
/
AddressVerificationOutput
. This makes it much clearer what the data structures are use for, and if you e.g. break that step into "billing address" and "home address" steps, you only have to change this step. Regarding using a map: we used that in our legacy system, and I hate it with passion: no type safety, refactoring is horribly complicated (esp. if developers get creative by creating "dynamic key computation functions"), and just try to find all the places where your "id" key/value pair is used.
e

edrd

07/08/2021, 8:02 PM
You could use interfaces + delegation by implementation to have all your step classes have all properties:
Untitled.kt
This way you only need to add the property to one of the interfaces and override it in its respective data class
👀 1
q

Quincy

07/09/2021, 1:42 PM
That's a really nice idea @edrd
🤘 1
d

DALDEI

10/03/2021, 3:02 AM
(late to party) - I had a similar problem with code generation from CSV schema. Many of the records were nearly but not quite identical. Contained many common subsets of fields like FirstName/LastName, Address(1,2,3) , OrderNumber etc. But they didn't really fit into a class hierarchy and the code generator didn't have the capability of modeling anything other then flat. An architecture I considered (but did not implement - yet) was to have the code generator (or manual) create an Interface Per Property interface LastName { val lastName : String } ... data class Order( override val firstName : String , override val lastName : String ) : .. , FirstName , LastName Given many data classes that shared fields they would now share interfaces Allowing to instead of copy, create arbitrary collections of fields in a class by interface and use it by refrence. interface FancyOrder : FirstName, LastName, OrderNumber .> val order : Order = order(...) val fancyOrder : FancyOrder = order // Works if FancyOrder has a subset of interface parents as Order One reason I didnt implement this is I could hear the compiler exploding in my head.
View count: 3