line / armeria

Your go-to microservice framework for any situation, from the creator of Netty et al. You can build any type of microservice leveraging your favorite technologies, including gRPC, Thrift, Kotlin, Retrofit, Reactive Streams, Spring Boot and Dropwizard.
https://armeria.dev
Apache License 2.0
4.82k stars 916 forks source link

Add Kotlin as a optional dependency of core module. #4229

Open ikhoon opened 2 years ago

ikhoon commented 2 years ago

If Kotlin dependency is added to an optional dependency, we can provide Kotlin-specific extension methods and DSL for each module. For example:

// WebClientExtensions.kt
inline fun <reified T> WebClientRequestPreparation.asJson():
        FutureTransformingRequestPreparation<ResponseEntity<T>> {
    return asJson(object : TypeReference<T>() {})
}

val response: ResponseEntity<Item> = 
  client.prepare()
        .get("/example")
        .asJson<Item>()  // Simply specify the target type parameter.
        .execute()
jimexist commented 2 years ago

by the way i added kotlin support in thrift some time ago, could benefit from that once libthrift and compiler 0.17.0 is released in Q3 2022

ikhoon commented 2 years ago

It looks to support Kotlin Coroutines. Awesome! ❤️ https://github.com/apache/thrift/blob/master/compiler/cpp/src/thrift/generate/t_kotlin_generator.cc#L1393

jimexist commented 2 years ago

It looks to support Kotlin Coroutines. Awesome! ❤️ https://github.com/apache/thrift/blob/master/compiler/cpp/src/thrift/generate/t_kotlin_generator.cc#L1393

yes i intended to only support suspend functions, but then (for the default implementation) delegate to jdk8 bridge for suspend function <=> async client operations, so that the generated code can still work with the existing Java libthrift library alone, i.e. there's no libthrift-kotlin library.

i can see that in armeria the thrift client is actually not based on the default implementation but rather via dynamic proxy and delegate in order to work upon HTTP protocol, so ideally this can be done similarly for kotlin