Skip to content

feat: JSON:API Atomic Operations extension support (v2.2.0)#2

Open
treere wants to merge 1 commit into
jsonapi1.1from
atomic
Open

feat: JSON:API Atomic Operations extension support (v2.2.0)#2
treere wants to merge 1 commit into
jsonapi1.1from
atomic

Conversation

@treere
Copy link
Copy Markdown
Owner

@treere treere commented May 22, 2026

Summary

Implements support for the JSON:API Atomic Operations extension, allowing clients to submit a batch of add, update, and remove operations in a single request. Atomicity at the database level remains the responsibility of the calling application.

This PR targets the jsonapi1.1 branch and builds on top of the JSON:API 1.1 changes introduced in #1.

New Modules

JSONAPIPlug.AtomicPlug

A Plug.Builder-based pipeline for Atomic Operations endpoints. It:

  • Enforces POST method (returns 405 otherwise).
  • Delegates content-type negotiation and response content-type to the existing plugs.
  • Parses and normalizes the atomic:operations request body via AtomicParams.
  • Accepts api: and resources: options; resolves JSON:API type strings to resource modules at init time.

JSONAPIPlug.Document.AtomicOperation

Struct representing a single operation object within an atomic:operations document. Deserializes op, ref, href, data, and meta members; validates that op is one of add, update, or remove; enforces mutual exclusion of ref and href.

JSONAPIPlug.Document.OperationRef

Struct representing the ref member of an operation object. Requires a non-empty type and either id or lid; optionally carries a relationship member.

Changes to Existing Modules

JSONAPIPlug (main module)

  • Added operations and resource_types fields to the %JSONAPIPlug{} struct.
  • Added render_atomic/3: renders an atomic:results document from a list of {resource_or_nil, meta_or_nil} tuples. Returns nil when all results are empty, signalling a 204 No Content response.

JSONAPIPlug.Document

  • Added operations and results fields to %Document{}.
  • deserialize/1 now handles atomic:operations documents; raises InvalidDocument on mutual exclusion violations (e.g. atomic:operations + data) or an empty operations array.
  • serialize/1 handles atomic:results documents, encoding results under the atomic:results key.

JSONAPIPlug.Normalizer

  • denormalize/3 updated to handle atomic operation lists: returns a list of Conn.params() (one per operation) instead of a single params map.

@treere treere changed the title feat: JSON:API Atomic Operations extension (https://jsonapi.org/ext/a… feat: JSON:API Atomic Operations extension support (v2.2.0) May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant