Skip to main content

API overview

:::info Implemented by cmd/api and cmd/a2a cmd/api serves every REST route below (internal/adapters/inbound/http) on HTTP_ADDR (default :8080); cmd/a2a serves the agent on A2A_ADDR (default :8093). The contracts are apis/openapi.yaml and apis/asyncapi.yaml. The router registers exactly the eleven API routes plus /healthz and /readyz; the only HTTP route that is not in the OpenAPI file is the A2A endpoint /a2a, described below. See the Quickstart for the shapes of the answers. :::

InterfaceSource of truthNotes
RESTapis/openapi.yaml (OpenAPI 3.0.3, version 0.1.0)The pages under REST in the sidebar are generated from the spec with npm run gen-api-docs; do not edit them by hand. The spec names http://localhost:8080; in the kind cluster the service is behind Kong at /api/shopping-cart (prefix stripped).
Eventsapis/asyncapi.yaml (AsyncAPI 3.0.0, version 1.0.0)Four published events and seven consumed ones, on the event catalogue; every field on Domain events.
MCPADR 0009, MCP tools, internal/adapters/inbound/mcpcmd/mcp, Streamable HTTP on /mcp (port 8090; through the gateway /api/mcp/shopping-cart, off by default in the chart). Two read-only tools (get_cart, list_shopper_carts), each authority L1, one resource and one prompt; no write tool. No auth, by fleet decision.
A2AADR 0006, internal/adapters/inbound/a2acmd/a2a, JSON-RPC 2.0 on / and /a2a (port 8093; through Kong /api/a2a/shopping-cart), Agent Card at /.well-known/agent-card.json. Two read-only skills, no write skill. No auth, by fleet decision.

Endpoints​

All carry the cart view on success (see cart view). Every POST requires an Idempotency-Key header.

TagEndpointOperation idSuccessErrors
CartsPOST /cartscreateCart201, an empty OPEN cart; body optional {"shopperId"}422
CartsGET /carts?shopperId=&state=listCarts200 {"carts": [...]}, newest first422 (missing or invalid shopperId, unknown state)
CartsGET /carts/{cartId}getCart200, the cart with quote, selections, estimate, readiness404
LinesPOST /carts/{cartId}/linesaddCartLine200; {"catalogItemId","quantity"}; merges into an existing line404, 409, 422
LinesPUT /carts/{cartId}/lines/{catalogItemId}setCartLineQuantity200; {"quantity"}404, 409, 422
LinesDELETE /carts/{cartId}/lines/{catalogItemId}removeCartLine200404, 409
DeliveryPUT /carts/{cartId}/destinationsetCartDestination200; {"destinationPostalPrefix"}404, 409, 422
DeliveryPOST /carts/{cartId}/delivery-quotesquoteCartDelivery200; no body; calls delivery-promise404, 409, 422, 503
DeliveryPUT /carts/{cartId}/delivery-selectionselectCartDelivery200; {"groupNo","offerId"}404, 409, 422
CartsPOST /carts/{cartId}/mergesmergeCartInto200, the target cart; {"targetCartId"}404, 409, 422
DeliveryPOST /carts/{cartId}/delivery-requote-acceptancesacceptRequotedOffers200; {"offers": [...]} replaces quote and selections without calling delivery-promise404, 409, 422
HealthGET /healthz, GET /readyznone (not in the spec)200 {"status":"ok"} / 200 {"status":"ready"}; /readyz answers 503 once shutdown starts or Postgres or Kafka is unreachable

/healthz and /readyz are registered by the router but are not described in apis/openapi.yaml.

The cart view​

Every cart answer is the same document (cartBody, internal/adapters/inbound/http/dto.go):

FieldMeaning
cartId, shopperId (null for a guest), state (OPEN, CHECKED_OUT, ABANDONED, MERGED)identity and lifecycle
lines[{catalogItemId, quantity}], one per item, in cart order
destinationPostalPrefixnull until set
deliveryQuoteabsent until quoted: groups[{groupNo, lineNos, offers[{offerId, groupNo, tier, deliverByEarliest, deliverByLatest, expiresAt}]}], unavailable[{tier, constraint, groupNo?}], unavailableTiers, quotedAt
selections[{groupNo, offerId}]
estimatecurrency, itemsMinor, deliveryMinor, taxMinor, totalMinor, estimateComplete. Labelled and non-binding
checkoutReadinessready, allGroupsSelected, noOfferExpired
versionthe optimistic-concurrency token; +1 per change

Conventions in the contract​

  • Idempotency. Idempotency-Key (1 to 128 characters) is required on all nine POST routes: absent or longer is 400 idempotency-key-required. A 2xx answer and a refusal that is FINAL for the request (ADR 0011: malformed-request, quantity-out-of-range, validation-failed, cart-closed) are stored for 24 hours and replayed with the header Idempotency-Replayed: true; a RETRYABLE refusal (not-found, concurrent-update, stale-delivery-selection, item-not-purchasable, too-many-lines, no-destination, merge-target, illegal-transition) and a 5xx are never stored: the key is released and the same key runs the request again. The same key with a different method, path, query or body against a stored answer is 409 idempotency-key-reused. POST /carts/{cartId}/delivery-quotes forwards its key to delivery-promise.
  • Errors are RFC 9457 application/problem+json with type /problems/<slug>. The slugs: malformed-request, idempotency-key-required, not-found, resource-not-found, cart-closed, stale-delivery-selection, illegal-transition, concurrent-update, item-not-purchasable, quantity-out-of-range, too-many-lines, no-destination, merge-target, validation-failed, idempotency-key-reused, delivery-promise-unavailable, dependency-unavailable and internal-error. Status and cause of each are on Troubleshooting; the detail of a 500 is fixed text, the cause is only in the log.
  • Ids. Opaque, 1 to 64 characters from A-Z a-z 0-9 . _ : -, starting with a letter or digit.
  • Bounds. Quantity 1 to 99 per line; at most 100 lines; destination prefix 1 to 10 letters or digits; request bodies are size-limited and unknown JSON fields are rejected (malformed-request).
  • Money is integer minor units; estimateComplete: false means the figures cover only what is known (no destination, an unpriced line, an unselected group, or no tax band for the prefix).
  • Concurrency. A write that loses the version race is retried once, then 409 concurrent-update.
  • Auth: none. REST, A2A and MCP are unauthenticated fleet-wide; TestNoAuthMiddlewareReintroduced fails CI if auth middleware returns.
  • Local calendar. deliverByEarliest and deliverByLatest are calendar dates in the destination's local time zone (ADR 0007).

A2A​

cmd/a2a is a message-only Agent2Agent agent (no streaming, no task lifecycle). The Agent Card is served at GET /.well-known/agent-card.json; it advertises the URL in A2A_AGENT_URL as a JSON-RPC interface and declares no security scheme. The JSON-RPC 2.0 endpoint is mounted at both / and /a2a; GET /healthz answers liveness.

A skill call is an A2A SendMessage request (JSON-RPC method SendMessage) whose first part is a data part (or a text part holding the same JSON) of the form {"skill": "<id>", "arguments": {...}}. The parsing is strict: unknown fields are rejected.

SkillArgumentsSame asAnswer
get_cartcartId (required)GET /carts/{cartId}data.cart, the cart view, for a cart of any state
list_shopper_cartsshopperId (required), state (optional: OPEN, CHECKED_OUT, ABANDONED, MERGED)GET /carts?shopperId=&state=data.carts, newest first; an empty list for a shopper with none
curl -s localhost:8093/a2a -H 'Content-Type: application/json' -d '{
"jsonrpc":"2.0","id":1,"method":"SendMessage",
"params":{"message":{"role":"ROLE_USER","messageId":"m-1",
"parts":[{"data":{"skill":"get_cart","arguments":{"cartId":"cart-123"}}}]}}}'

The request shape above is the one cmd/a2a/router_test.go sends; the reply is one agent message with a data part carrying the envelope {skill, data | problem} and a text part with a one-line summary. Domain rejections are answered in the envelope as a problem with the REST slug and status (malformed-request and unknown-skill as 400, validation-failed as 422, not-found and resource-not-found as 404, internal-error as 500), never as a JSON-RPC error. The agent is read-only, calls no other context and has no outbound A2A client (TestA2ASurfaceIsReadOnly).