Skip to content
35 changes: 33 additions & 2 deletions topics/client-default-request.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ The [DefaultRequest](https://api.ktor.io/ktor-client/ktor-client-core/io.ktor.cl

## Install DefaultRequest {id="install_plugin"}

To install `DefaultRequest`, pass it to the `install` function inside a [client configuration block](client-create-and-configure.md#configure-client) ...
To install `DefaultRequest`, pass it to the `install` function inside a [client configuration block](client-create-and-configure.md#configure-client):

```kotlin
import io.ktor.client.*
import io.ktor.client.engine.cio.*
Expand All @@ -33,7 +34,7 @@ val client = HttpClient(CIO) {
}
```

... or call the `defaultRequest` function and [configure](#configure) required request parameters:
Or call the `defaultRequest` function and [configure](#configure) required request parameters:

```kotlin
import io.ktor.client.*
Expand Down Expand Up @@ -99,6 +100,36 @@ defaultRequest {
}
```

### Unix domain sockets

> Unix domain sockets are supported only in the CIO engine.
>
{style="note"}

You can [build individual requests with Unix domain sockets](client-requests.md#specify-a-unix-domain-socket),
but you can also configure a default request with a socket parameter.

To do that, pass a `unixSocket` call with the path to the socket to the `defaultRequest` function,
for example:

```kotlin
val client = HttpClient(CIO)

// Sending a single request to a Unix domain socket
val response: HttpResponse = client.get("/") {
unixSocket("/tmp/test-unix-socket-ktor.sock")
}

// Setting up the socket for all requests from that client
val clientDefault = HttpClient(CIO) {
defaultRequest {
unixSocket("/tmp/test-unix-socket-ktor.sock")
}
}

val response: HttpResponse = clientDefault.get("/")
```

## Example {id="example"}

The example below uses the following `DefaultRequest` configuration:
Expand Down
24 changes: 21 additions & 3 deletions topics/client-requests.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Learn how to make requests and specify various request parameters: a request URL
After [setting up the client](client-create-and-configure.md), you can make HTTP requests. The main way of making HTTP requests is the [request](https://api.ktor.io/ktor-client/ktor-client-core/io.ktor.client.request/request.html) function that can take a URL as a parameter. Inside this function, you can configure various request parameters:
* Specify an HTTP method, such as `GET`, `POST`, `PUT`, `DELETE`, `HEAD`, `OPTIONS`, or `PATCH`.
* Specify a URL as a string or configure URL components (a domain, a path, query parameters, etc.) separately.
* Specify a Unix domain socket.
* Add headers and cookies.
* Set the body of a request, for example, a plain text, a data object, or form parameters.

Expand Down Expand Up @@ -119,6 +120,25 @@ You can configure a URL fragment using the `fragment` property.
Note that `fragment` [encodes][percent_encoding] a URL fragment.
To disable encoding, use `encodedFragment`.

## Specify a Unix domain socket

> Unix domain sockets are supported only in the CIO engine.
> To use a Unix socket with a Ktor server, [configure the server](server-configuration-code.topic#cio-code) accordingly.
>
{style="note"}

You can make requests to a server listening to a Unix domain socket by calling the `unixSocket` function
for a CIO client:

```kotlin
val client = HttpClient(CIO)

val response: HttpResponse = client.get("/") {
unixSocket("/tmp/test-unix-socket-ktor.sock")
}
```

You can also set up a Unix domain socket as a part of a [default request](client-default-request.md#unix-domain-sockets).

## Set request parameters {id="parameters"}
In this section, we'll see how to specify various request parameters, including an HTTP method, headers, and cookies. If you need to configure some default parameters for all requests of a specific client, use the [DefaultRequest](client-default-request.md) plugin.
Expand All @@ -134,8 +154,7 @@ To add headers to the request, you can use the following ways:
- The [header](https://api.ktor.io/ktor-client/ktor-client-core/io.ktor.client.request/header.html) function allows you to append a single header.
- The `basicAuth` and `bearerAuth` functions add the `Authorization` header with a corresponding HTTP scheme.
> For advanced authentication configuration, refer to [](client-auth.md).




### Cookies {id="cookies"}
To send cookies, use the [cookie](https://api.ktor.io/ktor-client/ktor-client-core/io.ktor.client.request/cookie.html) function:
Expand All @@ -147,7 +166,6 @@ To send cookies, use the [cookie](https://api.ktor.io/ktor-client/ktor-client-co
Ktor also provides the [HttpCookies](client-cookies.md) plugin that allows you to keep cookies between calls. If this plugin is installed, cookies added using the `cookie` function are ignored.



## Set request body {id="body"}
To set the body of a request, you need to call the `setBody` function exposed by [HttpRequestBuilder](https://api.ktor.io/ktor-client/ktor-client-core/io.ktor.client.request/-http-request-builder/index.html). This function accepts different types of payloads, including plain text, arbitrary class instances, form data, byte arrays, and so on. Below, we'll take a look at several examples.

Expand Down
5 changes: 2 additions & 3 deletions topics/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,11 @@ plugins {
</tabs>

> The Docker integration is automatically disabled if you apply the Ktor Gradle plugin along with the Kotlin Multiplatform Gradle plugin.
> To use this feature with KMP, you'll need to move the Ktor plugin to a separate project:
> To be able to use them together:
> 1. Create a JVM-only project with the Ktor Gradle plugin applied as shown above.
> 2. Add the Kotlin Multiplatform project as a dependency to that JVM-only project.
>
> If in your case it is necessary to apply both Gradle plugins in the same project,
> let us know by leaving a comment in [KTOR-8464](https://youtrack.jetbrains.com/issue/KTOR-8464).
> If this workaround does not solve the problem for you, let us know by leaving a comment in [KTOR-8464](https://youtrack.jetbrains.com/issue/KTOR-8464).
>
{style="warning"}

Expand Down
7 changes: 3 additions & 4 deletions topics/server-fatjar.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ To build a fat JAR, you need to configure the Ktor plugin first:
{src="snippets/deployment-ktor-plugin/build.gradle.kts" include-lines="28-31,53"}

> The fat JAR creation feature is automatically disabled if you apply the Ktor Gradle plugin along with the Kotlin Multiplatform Gradle plugin.
> To use this feature with KMP, you'll need to move the Ktor plugin to a separate project:
> To be able to use them together:
> 1. Create a JVM-only project with the Ktor Gradle plugin applied as shown above.
> 2. Add the Kotlin Multiplatform project as a dependency to that JVM-only project.
>
> If in your case it is necessary to apply both Gradle plugins in the same project,
> let us know by leaving a comment in [KTOR-8464](https://youtrack.jetbrains.com/issue/KTOR-8464).
>
> If this workaround does not solve the problem for you, let us know by leaving a comment in [KTOR-8464](https://youtrack.jetbrains.com/issue/KTOR-8464).
>
{style="warning"}

Expand Down
31 changes: 31 additions & 0 deletions topics/whats-new-320.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,37 @@ Ktor’s HTMX support is available across three experimental modules:
All APIs are marked with `@ExperimentalKtorApi` and require opt-in via `@OptIn(ExperimentalKtorApi::class)`.
For more information, see [](htmx-integration.md).

## Unix domain sockets

With 3.2.0, you can set up Ktor clients to connect to Unix domain sockets and Ktor servers to listen to such sockets.
Currently, Unix domain sockets are only supported in the CIO engine.

Example of a server configuration:

```kotlin
val server = embeddedServer(CIO, configure = {
unixConnector("/tmp/test-unix-socket-ktor.sock")
}) {
routing {
get("/") {
call.respondText("Hello, Unix socket world!")
}
}
}
```

Connecting to that socket using a Ktor client:

```kotlin
val client = HttpClient(CIO)

val response: HttpResponse = client.get("/") {
unixSocket("/tmp/test-unix-socket-ktor.sock")
}
```

You can also use a Unix domain socket in a [default request](client-default-request.md#unix-domain-sockets).

## Infrastructure

### Published version catalog
Expand Down