java.net.http.HttpClient and has no runtime dependencies. Every call has a blocking form and an async form that returns a CompletableFuture.
- Package:
dev.caretly:caretly - Source:
clients/java
Install
The client needs Java 11 or newer.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:Sync and async
Every call has an...Async form that returns a CompletableFuture:
join(), they’re wrapped in a CompletionException.
Render a page as PNG
A PNG holds one page. Choose it withpage, 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 withRenderOptions.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 extendCaretlyException:
ApiException has statusCode(), getMessage() (the response body) and retryAfter() (Optional<Duration>).
Retries and idempotency
The client retries429, 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.