API Standards
Source references:
Architecture- API Guidelines.md;
Architecture- API.md;
Architecture- Internal API.md;
API- Azure API Management (APIM).md.
Scope
Every service in ION exposes at most three interfaces — the Trilateral API (§10 in principles):
- Publish — events emitted on the shared Service Bus namespace.
- Subscribe — events consumed from other services’ topics.
- REST (HTTP/JSON) — synchronous commands and reads.
This document is the platform-wide contract for all three. Individual services extend it in their own service page but MUST NOT contradict it.
1. REST (HTTP/JSON) standards
1.1 Style
- MUST use REST + JSON:API (ADR-0009). No GraphQL, no bespoke JSON shapes.
- MUST publish an OpenAPI 3.x spec, versioned in the service repo, linked from the service page.
- MUST front public APIs through the shared APIM in the spoke (ADR-0017).
- MUST NOT call another ION service synchronously to fulfil a domain operation (§5). REST is for the caller boundary (BFF or external client), not for cross-service orchestration.
1.2 Resource design
- MUST model resources as nouns, plural:
/incidents,/tickets,/service-requests. - MUST use kebab-case in path segments; camelCase in JSON fields.
- MUST identify resources by opaque UUIDs — no sequential IDs, no customer-visible internal keys.
- SHOULD keep hierarchy shallow (
/incidents/{id}/comments); avoid nesting > 2 levels — flatten with query filters instead.
1.3 Verbs & semantics
- MUST honour HTTP verbs:
GETsafe,HEADsafe,PUTidempotent,PATCHfor partial (RFC 7396 or JSON:API patch),POSTfor non-idempotent commands (make them idempotent by key at the handler). - MUST honour status codes:
200,201 Created(+Location),202 Accepted(async write — Async REST),204,400,401,403,404,409(conflict),412(precondition),422(unprocessable),429(throttled),500,503,504. - MUST return
Location+ correlation-ID header on202and define an ack channel (SignalR / event) for completion.
1.4 Request & response shape
- MUST JSON:API envelope:
data,included,meta,links,errors. - MUST error responses use JSON:API
errors[]withstatus,code,title,detail,source, and a stable machine-readablecode. - MUST RFC 3339 timestamps in UTC (
2025-08-25T12:34:56.789Z). - MUST currency as ISO 4217 code + integer minor units; never floats.
- MUST UTF-8 everywhere.
1.5 Filtering, sorting, sparse fields
- MUST filter via
filter[<field>][<op>]=<value>(JSON:API convention). Supported ops:eq,ne,in,nin,gt,ge,lt,le,contains,startsWith. - MUST sort via
sort=field,-otherField(leading-for descending). - SHOULD support sparse fieldsets:
fields[resource]=a,b,c.
1.6 Pagination — cursor-based
- MUST paginate lists using cursor-based pagination (ADR-0009). No offset/limit for public APIs.
- MUST request via
page[size]=N&page[after]=<opaque cursor>(andpage[before]for backwards).page[size]must have a hard max (typically 100) enforced by APIM. - MUST response includes
links.next,links.prev,meta.hasMore. No total count for large collections — providemeta.approxCountif needed. - MUST NOT expose store-internal cursors (Cosmos continuation tokens, SB sequence numbers). Encode + sign platform-neutral cursors.
1.7 Versioning
- MUST version via URL prefix:
/v1/incidents,/v2/incidents. - MUST additive changes in a version; breaking changes require a
new major version + deprecation window (min 6 months) +
Sunsetheader per RFC 8594. - MUST publish deprecation notices in APIM developer portal + release notes.
- SHOULD NOT use header-based versioning — URL is auditable in APIM + gateway logs.
1.8 Idempotency
- MUST accept
Idempotency-Keyheader on every unsafe write (POST, non-idempotentPATCH) and treat replays as no-ops (Idempotent Write). - MUST persist idempotency records with TTL ≥ client retry window.
1.9 Concurrency
- MUST support optimistic concurrency via
ETag+If-Matchfor updates on mutable entities. Conflict →412 Precondition Failed.
1.10 Rate limiting & quotas
- MUST rate limits enforced in APIM per-oid AND per-customer, documented in the endpoint table (ORR §G).
- MUST
429 Too Many RequestswithRetry-Afterheader on throttle. - SHOULD return
X-RateLimit-Remaining+X-RateLimit-Reset.
1.11 Auth
- MUST all public APIs require Entra ID JWT validated at APIM + capability-header validation (Auth / AuthZ, ADR-0012).
- MUST service-to-service via Managed Identity (ADR-0013). No client secrets in downstream calls.
- MUST authZ enforced at both UI and API layer via capability
scopes (
<DomainEntity>.<Read|ReadWrite>). - MUST NOT propagate user JWT past the BFF; downstream uses MI + capability token.
1.12 Observability
- MUST propagate
traceparent(W3C Trace Context) + correlation ID end-to-end. - MUST every request logged with correlation ID + customer / tenant tag (never PII).
- MUST APIs emit 4 golden signals per endpoint (Observability).
1.13 Health
- MUST
/healthz(liveness) +/readyz(readiness) endpoints — unauthenticated on internal path, MI-protected if publicly reachable.
2. Events — Publish / Subscribe
2.1 Envelope & schema
- MUST every event conforms to CloudEvents v1.0 + registered AsyncAPI channel spec (ADR-0004).
- MUST
typefollows the dotted convention:<platform>.<type>.<aggregateroot>.<name>.<version>, e.g.ion.event.securityincident.statusupdated.v1. - MUST
sourceis the producing service URN (urn:io:ontinue:ion:<service>);subjectis the aggregate ID;tenantIdextension carries the customer tenant;idis unique per emission. - MUST
datacontenttype: application/json; payload validated against AsyncAPI schema. - MUST custom extensions namespaced:
iontenant,ioncustomer,ioncorrelationid.
2.2 ECST — payload content
- MUST integration events carry the state consumers need (ECST). Consumers do not call back to the producer for state.
- MUST NOT publish PII beyond what is classified for the topic.
- SHOULD keep payload ≤ 256 KB for Service Bus. Blob-reference when larger.
2.3 Delivery & handling
- MUST publish onto the shared Service Bus namespace (ADR-0008).
- MUST consumers are idempotent and tolerate out-of-order + at-least-once delivery.
- MUST every subscription has a DLQ with alerts + replay tooling (DLQ).
- MUST producers + consumers respect throttling budgets (Service Bus Topic Throttling).
2.4 Versioning
- MUST additive-only within a major; new required fields → new major type (Schema Evolution).
- MUST publish deprecation timeline for retired schema versions.
2.5 Ordering & partitioning
- MUST partition by aggregate ID (session ID on SB) to preserve per-aggregate ordering.
- MUST NOT rely on cross-aggregate ordering.
3. Internal APIs (service-to-service)
- MUST NOT exist for domain operations — use events (§5, §6).
- MAY exist for query-only reads where the caller genuinely cannot use a projection (rare — document why).
- MUST internal reads go over private network + MI auth; never exposed via APIM.
4. Deprecation & sunsetting
- MUST deprecated endpoints emit
Sunsetheader + APIM analytics counter. - MUST removal only after ≥ 6-month deprecation period + zero traffic across all customers for ≥ 30 days.
- MUST consumer-side breakage announced through Pigeon / release-notes channel.
5. Testing
- MUST contract tests for every produced event + every consumed event.
- MUST OpenAPI spec used as the source of truth for request/response tests (schemathesis or equivalent).
- MUST load-test at target capacity before ORR sign-off.