Skip to main content
The Java client uses java.net.http.HttpClient and has no runtime dependencies. Every call has a blocking form and an async form that returns a CompletableFuture.

Install

The client needs Java 11 or newer.
The jar is the named module dev.caretly. With the module system, add requires dev.caretly; to your module-info.java.

Quickstart

Create a test key in the console and set it in your environment:
Render a label to PDF and save it:
Create one client and share it. It’s thread safe.

Sync and async

Every call has an ...Async form that returns a CompletableFuture:
Async calls complete exceptionally with the same exceptions as the blocking calls. When you call join(), they’re wrapped in a CompletionException.

Render a page as PNG

A PNG holds one page. Choose it with page, starting at 1:
client.renderPdf(zpl) is the matching shorthand for a PDF, and client.renderPng(zpl) renders the first page.

Render several files

renderFiles sends the files as multipart/form-data. Each file starts from a fresh printer state, and pages follow the order of the list:
ZplFile.of takes the ZPL as a String or byte[].

Render options

Build options with RenderOptions.builder(): Options you leave unset aren’t sent, so the server defaults apply. An invalid page or dpmm throws IllegalArgumentException. RenderOptions.defaults() uses every server default.

Read the result

Handle errors

All exceptions are unchecked and extend CaretlyException: ApiException has statusCode(), getMessage() (the response body) and retryAfter() (Optional<Duration>).

Retries and idempotency

The client retries 429, 503 and connection failures up to maxRetries times, 2 by default. It waits Retry-After when the server sends it. Otherwise it backs off 0.5 s, 1 s, 2 s, up to 8 s. Timeouts and other statuses aren’t retried. When retries are on and you don’t set an idempotencyKey, the client generates a UUID per call, so a retried render is never billed twice. Set your own key, such as an order number, to make retries across calls or processes safe too:

Configuration

Configure the client with the builder:
baseUrl also accepts a URI. Pass your own java.net.http.HttpClient to set a proxy, an executor or TLS settings.

Health check