Skip to main content

Konifer Client

The Konifer client wraps the HTTP API for Kotlin and Java. Version 0.2.0 supports JVM 17 or newer; Kotlin/Native and JavaScript targets are not part of this release.

Install the client​

Add Maven Central to your project's repositories and include the client dependency.

Gradle:

implementation("io.konifer:konifer-client:0.2.0")

For a Java project using Gradle, use io.konifer:konifer-client-jvm:0.2.0.

Maven:

<dependency>
<groupId>io.konifer</groupId>
<artifactId>konifer-client-jvm</artifactId>
<version>0.2.0</version>
</dependency>

Choose your client​

Use KoniferClient for suspending Kotlin calls or KoniferBlockingClient for blocking Java/JVM calls. Both expose the same operations and return KoniferResult<T>.

Build the client with your server's base URL, without /assets. Reuse it across requests and close it at application shutdown.

Store an image and get its URL​

Start the Quickstart server at http://localhost:8080. Run this example from the documentation repository, or replace static/img/konifer-small.png with your own PNG.

import io.konifer.client.KoniferClient
import io.konifer.common.image.ImageFormat
import java.nio.file.Files
import java.nio.file.Path

suspend fun main() {
val client = KoniferClient.build("http://localhost:8080")
try {
val assets = client.assets("users/123/profile-picture")
val image = Files.readAllBytes(Path.of("static/img/konifer-small.png"))

val asset = assets.newAsset()
.fromBytes(image, ImageFormat.PNG)
.withAlt("Konifer logo")
.store()
.valueOrThrow()

val link = assets.entry(asset.entryId)
.originalVariant()
.fetchLink()
.valueOrThrow()

println("Stored entry: ${asset.entryId}")
println(link.url)
} finally {
client.close()
}
}

Open the printed URL to view the stored image. The server's delivery configuration determines whether it points to Konifer, object storage, or a CDN.

Handle results​

Call valueOrThrow() to get the successful value or throw KoniferRequestException on failure. To recover from a request failure, inspect the KoniferResult instead: Failure.Http includes the HTTP status, stable error code, and optional message, while Failure.Transport and Failure.InvalidResponse include the underlying cause. Coroutine cancellation propagates as an exception.

Branch on code instead of parsing the message:

val result = client.assets("users/123/profile-picture").fetchInfo()
if (result is KoniferResult.Failure.Http) {
when (result.code) {
ErrorCode.NOT_FOUND -> println("No image found")
ErrorCode.UNKNOWN -> println("HTTP ${result.statusCode}: ${result.message}")
else -> println("${result.code}: ${result.message}")
}
}

Import io.konifer.client.KoniferResult and io.konifer.common.http.ErrorCode.

The client uses UNKNOWN for missing or unfamiliar codes and preserves the HTTP status and readable message. KoniferRequestException.failure exposes the same failure when you use valueOrThrow(). See Error Responses for the code/status table.

Optional configuration​

Pass hmacKey and the matching signing algorithm to build() if your server requires signed retrieval URLs. Use KoniferHttpConfiguration to set request, connection, and socket timeouts.

Next steps​

The API reference includes Kotlin and Java examples for each operation:

See Client content results for redirect metadata availability and streaming destination ownership.