Documentation/ Decision records
ADR 0017: The external API is versioned REST under `/api/v1`, with an RFC 7807 error body
Status: Accepted
Context
Karyo's HTTP API is called by its two front ends and by integrating systems. Internal calls between modules never use it: they are in-process injections and events (ADR 0008), so the REST surface is purely the external contract.
The warehouse domain has well-defined views - a stock list, an order and its lines, a pick list, a receipt - rather than ad-hoc client-driven queries. Clients need to know what a successful response looks like, how a failure is reported, and what may change without warning.
Decision
- One version, one prefix. Every resource is under
/api/v1, JSON over HTTP. Resource paths are kebab-case plural nouns (/stock-units,/delivery-orders); JSON fields are camelCase; domain actions are POST subpaths (/delivery-orders/{id}/release). - Versioning is URL-major and additive within a version. New fields are optional or defaulted, consumers tolerate unknown fields and enum values, and removing or changing a required field needs an explicit compatibility decision. There is no deprecation-header mechanism.
- Errors are RFC 7807 problem details. Mapped failures return a
ProblemDetailbody -type,title,status,detail,instance,traceId,timestamp- built by one exception mapper per module hierarchy, withtypeof the formhttps://karyowms.com/errors/<slug>. The HTTP status is the signal a client can always rely on. Each slug has exactly one meaning and one HTTP status across modules; sharing that meaning needs no module-qualified slug. The URL path identifies the resource, so a missing path resource is 404. Any other reference in the request input, whether in the body or in a query parameter, to something missing is 422invalid-reference. - Pagination, where a resource offers it, uses
PaginationParams(pagefrom 0,sizedefaulting to 20, repeatablesort) and returns aPaginatedResponseenvelope. Sort fields are checked against a per-resource allowlist. - Downloads carry their format in the path (
.csv,.pdf,.zpl), not through content negotiation. - No hypermedia. Clients know their routes; there are no
_links. - The contract is the source. The JAX-RS resources and the
-apiDTOs are the definition; no OpenAPI document is generated. /api/internal/is refused at the proxy.
Consequences
The contract as implemented has gaps a client must know about. Each is current behaviour:
- Every error raised by the application's own code, every JAX-RS refusal and every Quarkus
security-annotation refusal is a problem body,
served as
application/problem+json. Bare JAX-RS refusals, unreadable request bodies and faults no domain mapper claims are rendered by three mappers inlibs/karyo-common. A refusal from a Quarkus security annotation (@Authenticated, throughio.quarkus.security.UnauthorizedExceptionorForbiddenException) is rendered bySecurityRefusalMappersinservices/karyo-app, and a 401 keeps itsWWW-Authenticatechallenge. A lost optimistic-lock race is a 409concurrent-change, and any other unmapped fault is a 500internal-errorthat names an error id and carries no stack trace (the error contract). - Shared slugs keep one meaning and status.
not-found(404),validation-failed(400),duplicate-name(409),invalid-state-transition(409) andinvalid-reference(422) are shared deliberately.ProblemTypeConsistencyTestexecutes all application exception mappers and rejects a type with two statuses. Before 2.0.0, the error namespace moved to VoyagerForge's karyowms.com domain and missing body references across the affected modules changed to 422, through separate exceptions from genuine path-resource failures. Reference lists changed from 400 to 422; duplicate ordered references keep 400 with their own slug. This is a breaking API correction; clients comparing full type URIs or the former reference statuses must update them. The error contract lists the context-dependent legacy cases retained after the call-site audit. traceIdis always null because tracing is disabled (ADR 0025). Bean-validationdetailis prose joined from property paths and messages, not a structured field list.- Pagination is opt-in per resource. Many collections return a bare array with no total, and no
maximum
sizeis enforced. A misspelled sort field is dropped silently and the default order applies. Why some resources paginate and others do not is not recorded. - CSV exports stop at 10,000 rows and say so in the
X-Karyo-Truncatedheader and a trailing# truncated at 10000 rowsline, with status 200 and no way to fetch the rest. - Unknown query parameters are ignored, so a misspelled filter widens the result instead of failing.
- The
X-Correlation-Idheader is carried into the journal rows a request writes when the operation sets no correlation of its own (ADR 0010). - There is no machine-readable contract, no rate limiting, no CORS, and no idempotency keys or
entity tags. Why there is no OpenAPI document, why there is no rate limiting, and why downloads
select their format by path extension rather than by
Acceptare not recorded.
Alternatives considered
- GraphQL. Rejected. The domain's views are well defined, and a resolver layer, the N+1 loading problem and field-level authorisation are costs a set of targeted REST resources does not have.
- gRPC. Rejected. A binary protocol needs a proxy for browser clients and is harder to inspect, and at Karyo's call volumes the latency advantage over JSON is negligible.
- Hypermedia (HATEOAS). Rejected. The two front ends know their routes, and integrators use REST plus webhooks, not discovered links.
- Header or media-type versioning. Not recorded as considered.
Evidence
libs/karyo-common/src/main/kotlin/com/karyo/common/exception/ProblemDetail.kt,ProblemDetail- the one error bodylibs/karyo-common/src/main/kotlin/com/karyo/common/exception/ConstraintViolationExceptionMapper.kt,ConstraintViolationExceptionMapper- validation failures flattened to proselibs/karyo-common/src/main/kotlin/com/karyo/common/exception/ProblemDetailMediaTypeFilter.kt,ProblemDetailMediaTypeFilter- every problem body served asapplication/problem+jsonlibs/karyo-common/src/main/kotlin/com/karyo/common/exception/WebApplicationExceptionMapper.kt,WebApplicationExceptionMapper,MismatchedInputExceptionMapper.ktandUnhandledExceptionMapper.kt- bare JAX-RS refusals, unreadable bodies, lost races and unmapped faults kept on the contractservices/karyo-app/src/test/kotlin/com/karyo/app/errors/ErrorContractTest.kt,ErrorContractTest- the contract as a caller meets itlibs/karyo-common/src/main/kotlin/com/karyo/common/pagination/PaginationParams.kt,PaginationParamsandlibs/karyo-common/src/main/kotlin/com/karyo/common/pagination/SortParser.kt,SortParser- pagination parameters and sort parsinglibs/karyo-documents/src/main/kotlin/com/karyo/documents/CsvWriter.kt,CsvWriter.EXPORT_MAX_ROWS,CsvWriter.toResponse- the export cap and its truncation header and lineservices/karyo-app/src/main/resources/application.yaml,%dev.quarkus.otel.enabled, %prod.quarkus.otel.sdk.disabled- tracing disabled in development and productioninfrastructure/docker/nginx/nginx.conf,location /api/internal/-/api/internal/refused
Related
- ADR 0008 - REST outside the process, events inside it
- ADR 0016 - the same-origin clients of this API
- HTTP API surface - the surface in full
- API error contract - what a failure looks like on the wire
- Webhooks and the event catalogue - the push half of the contract