Skip to content

Commit

Permalink
Update samples
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr3zee committed Jan 13, 2025
1 parent d5ce101 commit b213f05
Show file tree
Hide file tree
Showing 23 changed files with 86 additions and 75 deletions.
3 changes: 3 additions & 0 deletions samples/ktor-all-platforms-app/.fleet/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"gradle.autoImportOnSave": false
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

import androidx.compose.animation.AnimatedVisibility
Expand All @@ -14,7 +14,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import io.ktor.client.*
import io.ktor.http.*
import kotlinx.rpc.krpc.ktor.client.installRPC
import kotlinx.rpc.krpc.ktor.client.installKrpc
import kotlinx.rpc.krpc.ktor.client.rpc
import kotlinx.rpc.krpc.ktor.client.rpcConfig
import kotlinx.rpc.krpc.serialization.json.json
Expand All @@ -28,7 +28,7 @@ expect val DEV_SERVER_HOST: String

val client by lazy {
HttpClient {
installRPC()
installKrpc()
}
}

Expand Down
8 changes: 4 additions & 4 deletions samples/ktor-all-platforms-app/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
kotlin = "2.0.21"
kotlin = "2.1.0"

agp = "8.8.0"
agp = "8.8.0-alpha05"
android-compileSdk = "35"
android-minSdk = "24"
android-targetSdk = "35"
Expand All @@ -13,13 +13,13 @@ androidx-espresso-core = "3.6.1"
androidx-material = "1.12.0"
androidx-test-junit = "1.2.1"
compose = "1.7.6"
compose-plugin = "1.8.0+check"
compose-plugin = "1.8.0-alpha01"
junit = "4.13.2"
ktor = "3.0.3"
logback = "1.5.16"
serialization = "1.8.0"
coroutines = "1.10.1"
kotlinx-rpc = "0.4.0"
kotlinx-rpc = "0.5.0"

[libraries]
# kotlin
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package kotlinx.rpc.sample
Expand All @@ -10,15 +10,15 @@ import io.ktor.server.application.*
import io.ktor.server.netty.*
import io.ktor.server.plugins.cors.routing.*
import io.ktor.server.routing.*
import kotlinx.rpc.krpc.ktor.server.RPC
import kotlinx.rpc.krpc.ktor.server.Krpc
import kotlinx.rpc.krpc.ktor.server.rpc
import kotlinx.rpc.krpc.serialization.json.json

fun main(args: Array<String>): Unit = EngineMain.main(args)

@Suppress("unused")
fun Application.module() {
install(RPC)
install(Krpc)

installCORS()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package kotlinx.rpc.sample
Expand All @@ -8,7 +8,7 @@ import UserData
import UserService
import io.ktor.server.testing.*
import kotlinx.coroutines.flow.toList
import kotlinx.rpc.krpc.ktor.client.installRPC
import kotlinx.rpc.krpc.ktor.client.installKrpc
import kotlinx.rpc.krpc.ktor.client.rpc
import kotlinx.rpc.krpc.ktor.client.rpcConfig
import kotlinx.rpc.krpc.serialization.json.json
Expand All @@ -21,7 +21,7 @@ class ApplicationTest {
@Test
fun testRoot() = testApplication {
val service = createClient {
installRPC()
installKrpc()
}.rpc("/api") {
rpcConfig {
serialization {
Expand Down
2 changes: 1 addition & 1 deletion samples/ktor-all-platforms-app/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

@file:Suppress("UnstableApiUsage")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package kotlinx.rpc.sample.data

import io.ktor.client.HttpClient
import io.ktor.client.engine.okhttp.OkHttp
import io.ktor.client.request.url
import kotlinx.rpc.RPCClient
import kotlinx.rpc.krpc.ktor.client.installRPC
import kotlinx.rpc.RpcClient
import kotlinx.rpc.krpc.ktor.client.installKrpc
import kotlinx.rpc.krpc.ktor.client.rpc
import kotlinx.rpc.krpc.ktor.client.rpcConfig
import kotlinx.rpc.krpc.serialization.json.json

suspend fun createRpcClient(): RPCClient {
suspend fun createRpcClient(): RpcClient {
return HttpClient(OkHttp) {
installRPC()
installKrpc()
}.rpc {
url("ws://10.0.2.2:8080/api")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package kotlinx.rpc.sample.ui
Expand All @@ -14,14 +14,14 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
import kotlinx.rpc.RPCClient
import kotlinx.rpc.RpcClient
import kotlinx.rpc.krpc.streamScoped
import kotlinx.rpc.withService
import kotlinx.rpc.sample.MyService
import kotlinx.rpc.sample.UserData

class AppViewModel : ViewModel() {
private var rpcClient: RPCClient? = null
private var rpcClient: RpcClient? = null
private var apiService: MyService? = null

private val _uiState = MutableStateFlow<WelcomeData?>(null)
Expand Down Expand Up @@ -64,4 +64,4 @@ class AppViewModel : ViewModel() {
}
}
}
}
}
4 changes: 2 additions & 2 deletions samples/ktor-android-app/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
agp = "8.8.0"
kotlin = "2.0.21"
kotlin = "2.1.0"
androidx-activityCompose = "1.9.3"
androidx-appcompat = "1.7.0"
androidx-constraintlayout = "2.2.0"
Expand All @@ -15,7 +15,7 @@ ktor = "3.0.3"
kotlinx-serialization-json = "1.8.0"
kotlinx-coroutines-core = "1.10.1"
logback = "1.5.16"
kotlinx-rpc = "0.4.0"
kotlinx-rpc = "0.5.0"

[libraries]
# kotlin
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/
package kotlinx.rpc.sample

import io.ktor.server.application.*
import io.ktor.server.cio.*
import io.ktor.server.routing.*
import io.ktor.server.websocket.*
import kotlinx.rpc.krpc.ktor.server.Krpc
import kotlinx.rpc.krpc.ktor.server.rpc
import kotlinx.rpc.krpc.serialization.json.json

fun main(args: Array<String>): Unit = EngineMain.main(args)

@Suppress("unused")
fun Application.module() {
install(WebSockets)
install(Krpc)

routing {
rpc("/api") {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

import io.ktor.client.request.*
Expand All @@ -9,7 +9,7 @@ import io.ktor.server.response.*
import io.ktor.server.routing.*
import io.ktor.server.testing.*
import kotlinx.coroutines.flow.toList
import kotlinx.rpc.krpc.ktor.client.installRPC
import kotlinx.rpc.krpc.ktor.client.installKrpc
import kotlinx.rpc.krpc.ktor.client.rpc
import kotlinx.rpc.krpc.ktor.client.rpcConfig
import kotlinx.rpc.krpc.serialization.json.json
Expand All @@ -24,7 +24,7 @@ class ApplicationTest {
@Test
fun testRoot() = testApplication {
val service = createClient {
installRPC()
installKrpc()
}.rpc("/api") {
rpcConfig {
serialization {
Expand Down
3 changes: 0 additions & 3 deletions samples/ktor-web-app/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# Ktor Web App
Sample application with Kotlin/Js on frontend and Kotlin/Jvm on backend,that uses kRPC with Ktor to communicate.

> Warning: the code is broken due to https://youtrack.jetbrains.com/issue/KT-71757/
> No workarounds for now
### Running frontend
To run frontend in development mode, run this command:
```bash
Expand Down
1 change: 1 addition & 0 deletions samples/ktor-web-app/frontend/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ kotlin {
implementation(libs.kotlin.stdlib.js)
implementation(libs.ktor.client.js)
implementation(libs.ktor.client.websockets.js)
implementation(libs.kotlinx.rpc.core)
implementation(libs.kotlinx.rpc.krpc.ktor.client)
implementation(libs.kotlinx.rpc.krpc.serialization.json)

Expand Down
4 changes: 2 additions & 2 deletions samples/ktor-web-app/frontend/src/jsMain/kotlin/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

import kotlinx.rpc.RPCClient
import kotlinx.rpc.RpcClient
import kotlinx.rpc.withService
import react.FC
import react.Props
Expand All @@ -11,7 +11,7 @@ import react.useEffectOnce
import react.useState

val App = FC<Props> {
var rpcClient by useState<RPCClient?>(null)
var rpcClient by useState<RpcClient?>(null)

useEffectOnce {
rpcClient = initRpcClient()
Expand Down
8 changes: 4 additions & 4 deletions samples/ktor-web-app/frontend/src/jsMain/kotlin/RPC.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
import io.ktor.client.*
import io.ktor.client.engine.js.*
import io.ktor.client.request.*
import kotlinx.rpc.RPCClient
import kotlinx.rpc.krpc.ktor.client.installRPC
import kotlinx.rpc.RpcClient
import kotlinx.rpc.krpc.ktor.client.installKrpc
import kotlinx.rpc.krpc.ktor.client.rpc
import kotlinx.rpc.krpc.ktor.client.rpcConfig
import kotlinx.rpc.krpc.serialization.json.json

suspend fun initRpcClient(): RPCClient {
suspend fun initRpcClient(): RpcClient {
return HttpClient(Js) {
installRPC()
installKrpc()
}.rpc {
url("ws://localhost:8080/api")

Expand Down
4 changes: 2 additions & 2 deletions samples/ktor-web-app/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[versions]
kotlin = "2.0.21"
kotlin = "2.1.0"
kotlin-wrappers-bom = "2025.1.2"
ktor = "3.0.3"
kotlinx-serialization-json = "1.8.0"
kotlinx-coroutines-core = "1.10.1"
logback = "1.5.16"
kotlinx-rpc = "0.4.0"
kotlinx-rpc = "0.5.0"

[libraries]
# kotlin
Expand Down
4 changes: 2 additions & 2 deletions samples/ktor-web-app/server/src/main/kotlin/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import io.ktor.server.cio.*
import io.ktor.server.http.content.*
import io.ktor.server.plugins.cors.routing.*
import io.ktor.server.routing.*
import kotlinx.rpc.krpc.ktor.server.RPC
import kotlinx.rpc.krpc.ktor.server.Krpc
import kotlinx.rpc.krpc.ktor.server.rpc
import kotlinx.rpc.krpc.serialization.json.json

fun main(args: Array<String>): Unit = EngineMain.main(args)

@Suppress("unused")
fun Application.module() {
install(RPC)
install(Krpc)

installCORS()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

import io.ktor.server.testing.*
import kotlinx.coroutines.flow.toList
import kotlinx.rpc.krpc.ktor.client.installRPC
import kotlinx.rpc.krpc.ktor.client.installKrpc
import kotlinx.rpc.krpc.ktor.client.rpc
import kotlinx.rpc.krpc.ktor.client.rpcConfig
import kotlinx.rpc.krpc.serialization.json.json
Expand All @@ -21,7 +21,7 @@ class ApplicationTest {
}

val service = createClient {
installRPC()
installKrpc()
}.rpc("/api") {
rpcConfig {
serialization {
Expand Down
20 changes: 10 additions & 10 deletions samples/simple-ktor-app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

plugins {
kotlin("jvm") version "2.0.21"
kotlin("plugin.serialization") version "2.0.21"
kotlin("jvm") version "2.1.0"
kotlin("plugin.serialization") version "2.1.0"
id("io.ktor.plugin") version "3.0.3"
id("org.jetbrains.kotlinx.rpc.plugin") version "0.4.0"
id("org.jetbrains.kotlinx.rpc.plugin") version "0.5.0"
}

group = "kotlinx.rpc.sample"
Expand All @@ -28,17 +28,17 @@ kotlin {
}

dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-rpc-krpc-client:0.4.0")
implementation("org.jetbrains.kotlinx:kotlinx-rpc-krpc-server:0.4.0")
implementation("org.jetbrains.kotlinx:kotlinx-rpc-krpc-serialization-json:0.4.0")
implementation("org.jetbrains.kotlinx:kotlinx-rpc-krpc-client:0.5.0")
implementation("org.jetbrains.kotlinx:kotlinx-rpc-krpc-server:0.5.0")
implementation("org.jetbrains.kotlinx:kotlinx-rpc-krpc-serialization-json:0.5.0")

implementation("org.jetbrains.kotlinx:kotlinx-rpc-krpc-ktor-client:0.4.0")
implementation("org.jetbrains.kotlinx:kotlinx-rpc-krpc-ktor-server:0.4.0")
implementation("org.jetbrains.kotlinx:kotlinx-rpc-krpc-ktor-client:0.5.0")
implementation("org.jetbrains.kotlinx:kotlinx-rpc-krpc-ktor-server:0.5.0")

implementation("io.ktor:ktor-client-cio")
implementation("io.ktor:ktor-server-netty-jvm")
implementation("ch.qos.logback:logback-classic:1.5.16")

testImplementation("io.ktor:ktor-server-test-host")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:2.0.10")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:2.1.0")
}
Loading

0 comments on commit b213f05

Please sign in to comment.