Skip to content

Java client

A Java 17 client built on java.net.http.HttpClient. Its only dependency is Jackson (jackson-databind 2.x).

  • Coordinates: id.rightful:rightful-client:0.1.0-SNAPSHOT
  • Package: id.rightful.client

It is not published to a Maven repository yet. Ask us for a copy.

RightfulClient rightful = RightfulClient.builder()
.apiKey(System.getenv("RIGHTFUL_API_KEY")) // rk_test_… or rk_live_…
.baseUrl("https://api.rightful.id") // origin, without /v1
.timeout(Duration.ofSeconds(10))
.build(); // thread-safe: build one and share it
CreateSessionRequest req = CreateSessionRequest.builder("exam-entry", examineeId)
.namespace("org_" + orgId)
.locale("en")
.referenceImage("candidate_photo", candidatePhotoBytes)
.returnUrl(returnUrl)
.metadata(Map.of("exam_id", examId))
.build();
Session s = rightful.createSession(req, idempotencyKey);
// s.url() is returned only here: store it with s.id() before redirecting.
// Later:
Session now = rightful.getSession(s.id());
if (now.isTerminal()) { /* now.decision(): approved, declined or review */ }
// Or block in a background job:
Session done = rightful.awaitCompletion(s.id(), Duration.ofSeconds(3), Duration.ofMinutes(16));

Results are polled, or a webhook says when to fetch them (see below).

Method Endpoint
createSession(request, idempotencyKey) POST /v1/sessions (Idempotency-Key sent when the key is not null)
getSession(id) GET /v1/sessions/{id}
listSessions(), listSessions(namespace, subjectRef, status, limit) GET /v1/sessions
decideReview(id, decision, by, note) POST /v1/sessions/{id}/review
cancelSession(id) POST /v1/sessions/{id}/cancel
deleteSession(id) DELETE /v1/sessions/{id}
deleteSubject(namespace, subjectRef) DELETE /v1/subjects/{namespace}/{subject_ref}; returns the number erased
awaitCompletion(id, interval, timeout) Polls getSession until completed, expired or cancelled
putWorkflow(key, definition[, activate]) PUT /v1/workflows/{key} (JsonNode or Map)
validateWorkflow(definition) POST /v1/workflows/validate
getWorkflow(key[, version]) GET /v1/workflows/{key}
getTheme(), putTheme(theme) GET / PUT /v1/theme
compareFaces(byte[] reference, byte[] live) POST /v1/face/compare
verifyVoice(String referenceSession, byte[] wav, String trackId, String segmentLabel, String idempotencyKey) POST /v1/voice/verify
usage(), usage(from, to, groupBy) GET /v1/usage

The client does not wrap the evidence endpoints yet; call them directly. See the API reference.

Webhooks.verify(secret, header, rawBody) checks a Rightful-Signature header against the raw body with a 5-minute tolerance; an overload takes the tolerance and the current time. See Webhooks.

Every failure throws RightfulException, with code(), status() and detail():

  • API errors carry the server’s code, such as SESSION_NOT_FOUND, REFERENCE_IMAGES_MISMATCH or IDEMPOTENCY_KEY_REUSED. A structured detail comes back as JSON text.
  • A response without a code becomes HTTP_<status>.
  • Client-side failures are NETWORK_ERROR, AWAIT_TIMEOUT, INTERRUPTED or RESPONSE_INVALID, with status 0.
  • ReferenceImage(label, byte[]) is sent as {"label", "image": "<base64>"}. Null fields are left out of the request body.
  • metadata keys are sorted, so the same request always serialises to the same bytes. The server compares the raw body to detect a reused Idempotency-Key.
  • The client uses its own Jackson 2 ObjectMapper, so an app on Jackson 3 (tools.jackson) can still depend on it.