Skip to main content

API overview

:::info Implemented by cmd/api cmd/api serves every REST route below (internal/adapters/inbound/http/server.go) on HTTP_ADDR (default :8080). The contracts are apis/openapi.yaml (OpenAPI 3.0.3, document version 0.2.0) and apis/asyncapi.yaml (AsyncAPI 3.0.0, document version 1.1.0). The router registers exactly the ten operations of the spec plus /healthz and /readyz, which the spec does not list. See the Quickstart for real responses. :::

InterfaceSource of truthNotes
RESTapis/openapi.yamlThe pages under REST are generated from the spec with npm run gen-api-docs; do not edit them by hand. The only server named in the spec is http://localhost:8080; in the kind cluster the API is reached through Kong at http://localhost:8000/api/delivery-promise (prefix stripped).
Eventsapis/asyncapi.yamlThirteen published types and the consumed ones, see the event catalogue and Domain events.
MCPADR 0007, internal/adapters/inbound/mcpcmd/mcp serves Streamable HTTP on /mcp (also /) on port 8090; through Kong /api/mcp/delivery-promise rewritten to /mcp. Five read-only tools, no write tool: get_current_policy, get_delivery_offer, get_promise, list_promise_books, list_promises_by_order. See MCP tools. No auth, by fleet decision.
A2AADR 0010, internal/adapters/inbound/a2acmd/a2a serves JSON-RPC 2.0 on / and /a2a on port 8093 (through Kong /api/a2a/delivery-promise), the Agent Card at /.well-known/agent-card.json. Two read-only skills, no write skill: promise_status (exactly one of orderId, promiseId) and book_capacity (nodeId, date as YYYY-MM-DD). Requests must send A2A-Version: 1.0. Domain rejections are answered inside the message envelope as RFC 7807 problems with the REST classification (400, 404 not-found, 422 validation-failed, 500 internal-error), never as JSON-RPC errors. No auth, by fleet decision. /a2a is not in apis/openapi.yaml.

Endpoints​

TagEndpointOperation idSuccess
DeliveryOffersPOST /delivery-quotesquoteDeliveryOffers200 {offers, unavailable}; Idempotency-Key required; "no offer" is a normal answer
DeliveryOffersGET /delivery-offers/{offerId}getDeliveryOffer200, the offer in any state; 404 not-found
PromisesPOST /promisesmakePromise201 with Location; 200 on an idempotent replay; Idempotency-Key required
PromisesPOST /promises/{promiseId}/confirmationsconfirmPromise200, the promise; body orderId, groupNo; Idempotency-Key required
PromisesPOST /promises/{promiseId}/cancellationscancelPromise200; no body; Idempotency-Key required; checkout compensation
PromisesGET /promises/{promiseId}getPromise200; 404 not-found
PromisesGET /promises?orderId=listPromisesByOrder200 {items, nextCursor} keyset page (limit, cursor), one per group
PromiseBooksGET /promise-books?nodeId=&date=listPromiseBooks200 {items, nextCursor} keyset page; date is YYYY-MM-DD in the node's time zone
PromisePolicyPOST /promise-policiespublishPromisePolicy201, the new version; Idempotency-Key required
PromisePolicyGET /promise-policies/currentgetCurrentPromisePolicy200; version 0 (v0) when nothing was published
Health (not in the spec)GET /healthz, GET /readyznone200; /readyz is 503 while draining or when postgres or kafka is down
reportsGET /reports/promise-reliability?from=&to=getPromiseReliabilityReport200, per UTC day of judgement, tier and basis: judged, kept, broken, keptRate, broken by cause, lateness p50/p90 of the LATE ones. Served by cmd/dp-reports on :8092 (ADR 0018); 400 invalid-report-range
reportsGET /reports/promise-precision?from=&to=getPromisePrecisionReport200, per UTC day of PromiseMade and tier: promises made, window width mean/p50/p90 in minutes, exactDayShare, zoneUnknown, revisedShare, unkeepableCount
reportsGET /reports/quote-conversion?from=&to=getQuoteConversionReport200, per UTC day and tier: offers quoted, promises made, conversion (null without offers); plus promiseCoverage (ADR 0030), per UTC day and region (the first two characters of the destination postal prefix; top 10 by requests, the rest in other): requests, answeredWithPromise and the cumulative answeredWithinDays for 1, 2, 3 and 5 days, each with its share (null without requests). The unit of those fields is the offer quoted, not the request; the same region rows also carry requestsAnswered, requestsWithPromise, requestsWithinDays (1, 2, 3, 5) and requestShare (null without requests): the quote and estimate requests answered, with or without a promise (ADR 0032, best effort, only from the day DELIVERY_REQUEST_FACTS_ENABLED is switched on, 0 and null before)
reportsGET /reports/freshnessgetReportFreshness200, asOf and lagSeconds of the analytics projection (both null before the first event)

The quote route is the Open Host Service for storefront contexts; POST /promises, /confirmations, /cancellations, the policy and the books are called only by customer-ordering's checkout or by operators. Storefront contexts must never call the restricted routes.

Conventions in the contract​

  • Idempotency. Idempotency-Key is required on every POST, the quote included (NewRouter wraps POST /delivery-quotes in the idempotency middleware; a repeat of the same key and body returns the same offers). Missing: 400 idempotency-key-required. The key is global (not per route) and stored with a hash of method, path and body: the same key with the same request replays the stored status and body (header Idempotency-Replayed: true); any other request is 409 idempotency-key-reused; a key that is not 1-128 printable ASCII is 400 idempotency-key-invalid. A 2xx commits aggregates, outbox rows and the key together; a 4xx rolls the writes back but stores and replays the problem; a 5xx stores nothing. Keys are purged after 24 hours.
  • Errors are RFC 9457 application/problem+json, type = https://retailnetwork.example/problems/<slug> (see below).
  • Windows. A delivery window is two UTC instants (earliest, latest) plus the IANA timeZone of the destination delivery station, the local calendar its days belong to; timeZone is omitted only on an offer stored before ADR 0011 carried it.
  • Tiers are SAME_DAY, NEXT_DAY, TWO_DAY, STANDARD; basis is SCHEDULED, MEASURED or NOMINAL (NOMINAL only for STANDARD; MEASURED when a leg's measured transit pushed the arrival later, ADR 0014). An offer, an estimate option and a promise's terms may carry confidence, a number from 0 to 1 rounded to three decimals: the calibrated probability that the quote is kept on time (ADR 0020). It is omitted while the quote's segment has too few judged promises; absence means unknown, never zero.
  • Policy versions. policyVersion is v plus an integer; a publish stores the next version (strictly increasing) and a concurrent publish is 409 concurrent-update.
  • No personal data appears in any schema: the destination is a postal prefix, never an address.
  • Auth: none. The fleet reverted REST, MCP and A2A auth on 2026-09-11; TestNoAuthMiddlewareReintroduced fails CI if auth middleware returns. The in-cluster boundary is the access control.
  • Strict bodies. Request bodies are decoded with unknown fields refused (400 malformed-request), and NUL bytes are rejected by middleware.

Problems​

Source: internal/adapters/inbound/http/errors.go. The first matching entry wins; anything else is 500 internal-error with the cause withheld.

SlugStatusRaised when
malformed-request400body is not valid JSON for the operation, unknown field, wrong type
idempotency-key-required400state-changing POST without Idempotency-Key
not-found404offer, promise (or other resource) does not exist
offer-not-quotable409offer is EXPIRED or CONSUMED
promise-capacity-exhausted409book share reached, or the witness path is no longer feasible
book-closed409book CLOSED or past its hold deadline
promise-hold-expired409confirm after holdExpiresAt
promise-closed409promise is KEPT, BROKEN, RELEASED or CANCELLED
revision-moves-earlier409a revision would move deliverByLatest earlier
illegal-transition409command not legal in the current state (for example cancelling a PROVISIONAL promise)
concurrent-update409optimistic-concurrency race lost three times, or another policy version was published meanwhile
group-spans-nodes422a line is not shippable from the witness node
invalid-promise-terms422terms break shipBy < deliverByEarliest <= deliverByLatest
nominal-basis-not-allowed-for-tier422NOMINAL basis on a tier other than STANDARD
validation-failed422field-level validation (ids, lines 1 to 100, dates, policy bounds)
idempotency-key-reused422same key and route, different body
dependency-unavailable503/readyz only: postgres or kafka down
internal-error500anything unclassified or a recovered panic

The use cases that raise each error are on Use cases; symptoms and fixes on Troubleshooting.