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.
- Kotlin (suspending)
- Java (blocking)
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()
}
}
Save this program as Example.java.
import io.konifer.client.KoniferBlockingClient;
import io.konifer.common.image.ImageFormat;
import java.nio.file.Files;
import java.nio.file.Path;
public class Example {
public static void main(String[] args) throws Exception {
try (var client = KoniferBlockingClient.build("http://localhost:8080")) {
var assets = client.assets("users/123/profile-picture");
var image = Files.readAllBytes(Path.of("static/img/konifer-small.png"));
var asset = assets.newAsset()
.fromBytes(image, ImageFormat.PNG)
.withAlt("Konifer logo")
.store()
.valueOrThrow();
var link = assets.entry(asset.getEntryId())
.originalVariant()
.fetchLink()
.valueOrThrow();
System.out.println(link.getUrl());
}
}
}
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:
- Kotlin (suspending)
- Java (blocking)
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.
var result = client.assets("users/123/profile-picture").fetchInfo();
if (result instanceof KoniferResult.Failure.Http failure) {
switch (failure.getCode()) {
case NOT_FOUND -> System.out.println("No image found");
case UNKNOWN -> System.out.println("HTTP " + failure.getStatusCode());
default -> System.out.println(failure.getCode() + ": " + failure.getMessage());
}
}
Import io.konifer.client.KoniferResult.
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:
- Store assets
- Fetch assets, including content metadata, streaming, and pixel variants
- Update metadata
- Delete assets
- Evaluate rules
See Client content results for redirect metadata availability and streaming destination ownership.