diff --git a/topics/whats-new-340.md b/topics/whats-new-340.md index da5e809f8..c9a5bcbd6 100644 --- a/topics/whats-new-340.md +++ b/topics/whats-new-340.md @@ -429,6 +429,38 @@ val client = HttpClient { This allows you to explicitly override earlier default request configuration when composing or reusing client setups. +### Shared source set support for `js` and `wasmJs` targets + +Ktor now supports [Kotlin’s shared `web` source set](https://kotlinlang.org/docs/whatsnew2220.html#shared-source-set-for-js-and-wasmjs-targets) +in multiplatform projects, allowing you to share Ktor dependencies between `js` and `wasmJs` targets. This makes it +easier to share web-specific client code, such as HTTP clients and engines, across JavaScript and Wasm/JS. + +In your +build.gradle.kts +file, you can declare Ktor dependencies in `webMain`: + +```kotlin +kotlin { + sourceSets { + webMain.dependencies { + implementation("io.ktor:ktor-client-js:%ktor_version%") + } + } +} +``` + +You can then use APIs available to both `js` and `wasmJs` targets: + +```kotlin +// src/webMain/kotlin/Main.kt + +actual fun createClient(): HttpClient = HttpClient(Js) +``` + +> Existing .jsAndWasmShared.kt source files continue to work without changes. +> +{style="note"} + ## I/O ### Stream bytes from a `ByteReadChannel` to a `RawSink`