API Design
Developers and vendors delivering APIs for the organisation should also consult the Health New Zealand API Standards for protocol-specific design and implementation guidance.
Design Conventions
Summary
An API is designed around business-meaningful resources, using a protocol and conventions consistent across the organisation.
Standards
std-arch-design-conventions-01An API SHOULD expose resource-oriented, business-meaningful entities independently of its internal data structures and implementation details, at a granularity that avoids excessive fragmentation and coarseness.std-arch-design-conventions-02An API SHOULD encapsulate a multi-step internal business process behind a single operation so the consumer does not have to orchestrate the steps.std-arch-design-conventions-03Where a consumer-visible sequence of calls cannot be avoided, it MUST be included in the documented contract.std-arch-design-conventions-04Naming, structure, and resource conventions SHOULD be consistent across an organisation's APIs, so a consumer's experience integrating with one API transfers to another.std-arch-design-conventions-05An API for external or public consumption SHOULD use a widely-supported protocol compatible with external consumers, such as REST or GraphQL.std-arch-design-conventions-06gRPC MAY be used internally where all consumers are within the organisation's control.std-arch-design-conventions-07A new API SHOULD NOT be implemented using SOAP, a legacy protocol style.std-arch-design-conventions-08An existing SOAP-based API MAY continue to operate where replacing it is not yet justified.std-arch-design-conventions-09An HTTP-based API SHOULD use the standard status codes and headers defined in RFC 9110 to convey a request's outcome and response metadata.
Implements These Principles
Contract-First Design
Summary
An API's interface is defined in a machine-readable specification, kept current, and tested for conformance against it.
Standards
std-arch-contract-first-design-01An API's interface MUST be defined in a machine-readable specification, such as the OpenAPI Specification.std-arch-contract-first-design-02The specification MUST be kept current with the API's actual behaviour, so a consumer can rely on it without needing to seek guidance from the provider.std-arch-contract-first-design-03An API's implementation MUST be tested for conformance against its own specification, so the two cannot silently diverge.
Related Standards
Implements These Principles
Version Lifecycle
Summary
A breaking API change is introduced in a new version, a deprecated version remains supported through its notice period, and unused API surface is retired.
Standards
std-arch-version-lifecycle-01A published API version MUST NOT be changed in a way that breaks compatibility for its existing consumers.std-arch-version-lifecycle-02A breaking change MUST instead be introduced as a new version.std-arch-version-lifecycle-03An additive, non-breaking change SHOULD be preferred over introducing a new API version.std-arch-version-lifecycle-04A deprecated API version MUST remain supported for a defined notice period before retirement, communicated to its known consumers.std-arch-version-lifecycle-05A retirement date, once communicated, SHOULD NOT be brought forward.std-arch-version-lifecycle-06An API SHOULD NOT continue to expose a resource or operation that is no longer in active use, since unused surface area still carries a compatibility and security cost.
Implements These Principles
Authentication & Authorisation
Summary
Every caller is authenticated and individually accountable by default, using a standards-based protocol.
Standards
std-arch-authentication-authorisation-01Every API MUST require authentication and authorisation by default.std-arch-authentication-authorisation-02An API MAY be deliberately designed for anonymous access where public consumption is the intended use case.std-arch-authentication-authorisation-03Anonymous access MUST be an explicit design decision.std-arch-authentication-authorisation-04An API SHOULD use a recognised, standards-based authentication and authorisation protocol, such as OAuth 2.0 or OpenID Connect (OIDC), with a standard token format such as JSON Web Tokens (JWT).std-arch-authentication-authorisation-05A caller's identity MUST be individually attributable.std-arch-authentication-authorisation-06Shared or anonymous credentials MUST NOT be used for authenticated access.std-arch-authentication-authorisation-07Access granted to a caller MUST be limited to the specific resources and operations it requires.
Related Standards
Implements These Principles
Data Access & Jurisdiction
Summary
An API redacts what a caller is not authorised to see, and restricts data by the caller's jurisdiction.
Standards
std-arch-data-access-jurisdiction-01An API response MUST NOT include a confidential or sensitive field that the calling consumer is not authorised to view.std-arch-data-access-jurisdiction-02A confidential or sensitive field that the calling consumer is not authorised to view MUST be redacted or omitted before the response is returned.std-arch-data-access-jurisdiction-03An API exposing data subject to a residency or sovereignty requirement MUST be able to restrict access by the caller's jurisdiction.std-arch-data-access-jurisdiction-04Data subject to a residency or sovereignty requirement MUST NOT be served to a consumer outside an approved jurisdiction unless that cross-border flow has been identified and approved as its own requirement.
Implements These Principles
Input Validation & Error Handling
Summary
An API treats every input as untrusted, validates it, and returns errors through a consistent structure without leaking internal detail.
Standards
std-arch-input-validation-error-handling-01An API MUST validate all input against its specification and reject input that does not conform.std-arch-input-validation-error-handling-02Input received from a consumer MUST be treated as untrusted.std-arch-input-validation-error-handling-03Where input is passed to a database, command shell, or other interpreter, it MUST be handled through parameterisation or an equivalent safe mechanism to prevent injection.std-arch-input-validation-error-handling-04An API MUST return errors using a consistent, documented structure and status codes that a consumer can handle programmatically.std-arch-input-validation-error-handling-05An error response MUST NOT expose internal implementation detail, such as a stack trace or internal identifier, to the caller.
Implements These Principles
Rate Limiting & Compression
Summary
An API protects itself with a communicated rate limit, and compresses large responses without creating a side channel.
Standards
std-arch-rate-limiting-compression-01An API SHOULD protect itself against excessive demand from a single consumer through rate limiting or throttling.std-arch-rate-limiting-compression-02An API's rate limit or throttling threshold MUST be communicated to its consumers, so a consumer can design its own usage to remain within it.std-arch-rate-limiting-compression-03A consumer that exceeds a rate limit SHOULD receive a response that clearly indicates the limit has been exceeded and when it may retry.std-arch-rate-limiting-compression-04An API SHOULD support compression for large response payloads negotiated through standard HTTP content-coding headers.std-arch-rate-limiting-compression-05Compression MUST NOT be applied to a response that mixes confidential data with content influenced by the caller, since doing so can create a compression-based side channel that leaks the confidential data.
Implements These Principles
API Documentation
Summary
A published API is discoverable and has current documentation that a prospective consumer can understand unaided.
Standards
std-arch-api-documentation-01A published API MUST be discoverable by a prospective consumer without requiring direct access to the provider's source code or engineering team.std-arch-api-documentation-02Published documentation MUST describe the API's purpose, its resources and operations, and example usage.std-arch-api-documentation-03Published documentation MUST be kept current with the API's actual behaviour.std-arch-api-documentation-04Documentation MUST be published through an easily consumable mechanism, such as a web-accessible catalogue or portal.