# CRUD API Base Specification

Version: 0.2.0 · Status: draft · License: Apache-2.0

Source: lingodata/crud@bc225ba

## 1. Overview

The **CRUD API Base Specification** establishes a foundation for APIs that manage Resources through Create, Retrieve, Update and Delete operations. It defines operations, rules and a universal architecture independent of the protocol and of the data source.

The Base Specification is part of the **LingoData** family of specifications for data interoperability. It is derived into protocol specifications, such as HTTP and MCP, and complemented by optional extensions, such as asynchronous operations, Resource metadata and relationships. Within the family, Resources are represented in [ECSON](https://github.com/lingodata/ecson) and searched with [UnQuery](https://github.com/lingodata/unquery).

This specification consolidates rules and conventions from existing standards, common enterprise patterns and public APIs, while introducing some opinionated conventions to create a single source of truth (see [section 5](#5-origins-and-references)).

Although this document follows the IETF style, it is not an Internet Standards Track document (RFC), and it is not affiliated with any standards organization yet, including IETF, IANA, WHATWG, IEEE or ISO.

### 1.1 Conventions

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in BCP 14 ([RFC 2119](https://www.rfc-editor.org/rfc/rfc2119), [RFC 8174](https://www.rfc-editor.org/rfc/rfc8174)) when, and only when, they appear in all capitals, as shown here.

Normative rules are identified by a code (for example [`ID_KEY`](#ID_KEY)). Notes, examples and rationales are informative.

### 1.2 Versioning

<a id="SPEC_SEMVER"></a>**Rule `SPEC_SEMVER`**: MUST

This specification and every extension and protocol specification derived from it MUST be versioned independently, following [Semantic Versioning 2.0.0](https://semver.org/).

<a id="SPEC_BASE_RANGE"></a>**Rule `SPEC_BASE_RANGE`**: MUST

Every extension and protocol specification MUST declare the range of Base Specification versions it supports, as a SemVer range (for example `^0.2.0`).

> **Note (non-normative)**
>
> While a specification is in a `0.x` version, any release may contain incompatible changes, as allowed by Semantic Versioning. Version `1.0.0` is reserved for when the reference implementation and the conformance test suite validate the specification.

## 2. Terminology

### 2.1 CRUD Definition

**"CRUD"** is an acronym popularized in the early 1980s that encompasses two kinds of operations applied to Resources:

1. **Read operations**, such as querying, extracting and aggregating Resources;
2. **Write operations**, which change the current state of Resources.

### 2.2 Anatomy and behavior of a CRUD operation

A **CRUD operation** is made of:

```mermaid
classDiagram
	direction LR
    class Input
    Input : Subject
    Input : Parameters
    Input : Metadata
    
    class Output
    Output : Result
    Output : Metadata
    
    Input --> Output : produces
```

- **Input:** data used to perform the operation, broken down into:
    - **Subject:** the data the operation requires, such as Resources, Search Queries or Resource IDs;
    - **Parameters:** optional data that changes the behavior of the operation, such as sorting, projection and pagination; and
    - **Metadata:** data about the exchange itself, such as content negotiation (content type, encoding, serialization), operation metadata and Client and Server capabilities.
- **Output:** data returned by the operation, made of:
    - **Result:** the result data, whether Resources, an error or nothing; and
    - **Metadata:** the same kinds of metadata as the Input.

A CRUD operation involves the following **Participants**:

```mermaid
sequenceDiagram
    Client->>Protocol: sends Input via
    activate Protocol
    Protocol-->>Server: requests to
    Server->>Data source: performs operation in (through a Provider)
    activate Server
    Data source->>Server: returns Result
    deactivate Server
    Server-->>Protocol: responds using
    Protocol->>Client: returns Output to
    deactivate Protocol
```

- **Client**: the Participant that initiates the operation with standardized Input, for example a web server writing to a database or a mobile app requesting data from a web API.
- **Protocol**: the protocol that carries the Input to the Server and the Output back to the Client, such as HTTP or MCP, as defined by a protocol specification.
- **Server**: the Participant that performs the operation and returns the standardized Output, for example a web API or a database library that complies with this specification.
- **Data source**: where the Resources live and the operation is performed, such as a database, a file system or another API.
- **Provider**: the component of the Server that translates operations to a specific Data source.

### 2.3 The CRUD verbs

This specification defines a set of verbs that goes beyond the traditional CRUD acronym, as HTTP methods already do. "Retrieve" and "Update" are ambiguous and are split into distinct actions: `get` and `list`, `patch` and `replace`.

Given a Collection, the **CRUD verbs** are:

| Verb | Type | Description |
|---|---|---|
| `get` | Read | Retrieves a single Resource |
| `list` | Read | Lists Resources, optionally filtered by a Search Query (extensions, such as Views, may combine and process the result data) |
| `create` | Write | Creates one or many Resources |
| `patch` | Write | Updates Fields of one or many Resources |
| `replace` | Write | Fully replaces one or many Resources, with upsert capability |
| `delete` | Write | Removes one or many Resources |

### 2.4 The CRUD operations

Each verb is executed differently depending on the **Subject**, so the verbs are derived into the following **operations**, suffixed with the Subject type when a verb has more than one:

| Operation | Verb | Subject |
|---|---|---|
| `get` | `get` | The Resource ID |
| `list` | `list` | Nothing; or a Search Query |
| `create` | `create` | One or many Resources |
| `clone` | `create` | The Resource ID of a source Resource (+ an optional patch) |
| `patchById` | `patch` | The Resource ID + a patch |
| `patchByQuery` | `patch` | A Search Query + a patch |
| `replaceById` | `replace` | The Resource ID + a Resource |
| `replaceByQuery` | `replace` | A Search Query + a Resource |
| `deleteById` | `delete` | The Resource ID |
| `deleteByQuery` | `delete` | A Search Query |
| `listByView` | `list` | A View name ([Views extension](./views.md#14-execution-operation-listbyview)) |

### 2.5 Resources

Each term below is used consistently in this specification. Synonyms used by other tools are listed so readers can map them; they are not used in the rules.

- **Resource**: a data object uniquely identified within a Collection. Also called document, record, row, item or object.
- **Collection**: a set of Resources, identified by a Slug. A Collection does not imply a schema: Resources in the same Collection may have different Fields. Also called resource type, entity, table or database.
- **Field**: a key-value pair of a Resource. Also called property, attribute or column.
- **Resource ID**: the value, made of one or more Fields, that uniquely identifies a Resource within its Collection ([section 3.1.3](#313-resource-ids)).
- **Resource Representation**: the format, encoding and serialization used to transport a Resource during an operation, which may differ from how it is stored ([section 3.1.4](#314-resource-representation)).

> **Note (non-normative): Rationale**
>
> "Resource" follows [RFC 9110](https://www.rfc-editor.org/rfc/rfc9110), which distinguishes a resource from its representation.

### 2.6 General terminology

In addition to the terms above, this specification uses:

- **Slug**: An alphanumeric string in the format `^[a-zA-Z0-9_-]+$`, preferably lowercase.

- **`uuid-hex`**: A UUID represented in its **standard string format ([RFC 9562, section 4](https://www.rfc-editor.org/rfc/rfc9562#section-4))** (hexadecimal, lowercase, hyphens).

- **`uuid-base64url`**: A UUID byte array represented as a base64url-encoded string ([RFC 4648, section 5](https://www.rfc-editor.org/rfc/rfc4648#section-5)). Note that `base64url` replaces the 62nd and 63rd characters with `-` and `_` to make the encoding URL and filename safe.

## 3. General rules and definitions

This section defines rules and definitions that apply to many or all CRUD operations.

### 3.1 Resources

Resources, Collections, Fields, Resource IDs and Resource Representations are defined in [section 2.5](#25-resources).

#### 3.1.1 Collections

<a id="COLLECTION_SLUG"></a>**Rule `COLLECTION_SLUG`**: MUST

Collections in the same CRUD API MUST be uniquely identified by [Slugs](#26-general-terminology), regardless of language-specific typing or naming.

<a id="COLLECTION_NOT_FOUND"></a>**Rule `COLLECTION_NOT_FOUND`**: MUST

An operation on a Collection that does not exist MUST fail with the [`NOT_FOUND`](#NOT_FOUND) error, except as allowed by [`COLLECTION_CREATE_IMPLICIT`](#COLLECTION_CREATE_IMPLICIT).

<a id="COLLECTION_CREATE_IMPLICIT"></a>**Rule `COLLECTION_CREATE_IMPLICIT`**: MAY

A Server MAY create a Collection implicitly on the first `create` operation on it. A Server that does so MUST declare it.

> **Note (non-normative)**
>
> Schemaless Data sources, such as MongoDB, create collections on the first insert; others, such as relational databases, Notion or Airtable, cannot.

> **Note (non-normative)**
>
> This specification does not define schemas nor the discovery of Collections. Both are defined by the optional [Schema extension](./schema.md#1-schemas), which no other specification depends on.

#### 3.1.2 Fields

<a id="FIELDS_CAMEL_CASE"></a>**Rule `FIELDS_CAMEL_CASE`**: SHOULD

Fields in the same Collection SHOULD be formatted in camelCase.

<a id="FIELDS_NAMES"></a>**Rule `FIELDS_NAMES`**: MUST

A Field name MUST be a non-empty string. It MAY contain any character, including spaces and `.`, subject to [`FIELDS_NO_PREFIXES`](#FIELDS_NO_PREFIXES); nested Fields are addressed with the field path syntax of [UnQuery](https://github.com/lingodata/unquery) ([`PATH_DOT_NOTATION`](../unquery.md#PATH_DOT_NOTATION)), which defines how names with special characters are quoted.

> **Note (non-normative): Rationale**
>
> Data sources such as spreadsheets, Notion and Airtable often use names like `Customer name` or `Total.value`. Accepting them lets Providers expose existing data without renaming Fields; [`FIELDS_CAMEL_CASE`](#FIELDS_CAMEL_CASE) still recommends simple names for new APIs.

<a id="FIELDS_NO_PREFIXES"></a>**Rule `FIELDS_NO_PREFIXES`**: MUST NOT

Field names MUST NOT start with `$` or `@`. In the LingoData family, `$` marks ECSON typed values and `@` marks operators and control parameters.

<a id="FIELDS_RESERVED"></a>**Rule `FIELDS_RESERVED`**: MUST

Fields defined by this specification or by an extension, such as `_id`, are reserved and MUST be used only with the meaning defined for them. Other Field names MAY start with `_`.

<a id="FIELDS_EXTENSION_RESERVED"></a>**Rule `FIELDS_EXTENSION_RESERVED`**: SHOULD

Extensions that define reserved Fields SHOULD name them with a leading `_`, and MUST list them explicitly.

> **Note (non-normative): Rationale**
>
> With the ECSON escape convention, a Field named `$x` travels as `$$x`, and a Resource with a single Field `$meta` would read as a typed value. Metadata is carried by each Protocol (for example, HTTP headers and the MCP `_meta` object) and relationships use the ECSON `$rel` type, so Fields need no `$`. Many systems and libraries use `_` for their own Fields, so only the Fields explicitly defined by the specifications are reserved.

#### 3.1.3 Resource IDs

<a id="ID_KEY"></a>**Rule `ID_KEY`**: MUST

The `_id` field MUST be used to uniquely identify a Resource following the [Section 3.1.3 Resource IDs specs](#313-resource-ids) below, except when it is a composite key.

<a id="ID_SLUG"></a>**Rule `ID_SLUG`**: MUST

A Resource ID MUST be represented as a [Slug](#26-general-terminology), except when it is a composite key.

> **Tip (non-normative): Example**
>
> Valid Resource IDs: `0190a5f2-7c3e-7b1a-9f4e-2d8c6b1e4a90` (a UUIDv7 in `uuid-hex`), `AZCl8nw-exqfTi2MaxXkqQ` (the same UUID in `uuid-base64url`), `pt-br`, `order_1042`. Invalid: `order 1042` (space), `josé` (non-ASCII letter), `@views` (starts with `@`).

<a id="ID_UUID"></a>**Rule `ID_UUID`**: SHOULD

A Resource ID SHOULD be a UUID version 7 ([RFC 9562, section 5.7](https://www.rfc-editor.org/rfc/rfc9562#section-5.7)), represented in the `uuid-hex` format.

<a id="ID_UUID_BASE64URL"></a>**Rule `ID_UUID_BASE64URL`**: MAY

A UUID Resource ID MAY be represented in the [`uuid-base64url`](#26-general-terminology) format instead.

> **Note (non-normative): Rationale**
>
> UUIDv7 starts with a millisecond timestamp, so IDs are ordered by creation time, which keeps database indexes compact; RFC 9562 itself recommends it over versions 1 and 6. The `uuid-hex` format keeps that order when IDs are compared as strings, which is how many data sources store them; `uuid-base64url` is shorter (22 characters instead of 36) but its alphabet does not follow ASCII order, so string order no longer matches creation order.

<a id="ID_COMP_KEY_URLENCODED"></a>**Rule `ID_COMP_KEY_URLENCODED`**: MUST

Resource IDs made of many Fields (a.k.a. “composite keys”) MUST be represented in the format [`application/x-www-form-urlencoded`](https://url.spec.whatwg.org/#application/x-www-form-urlencoded).

#### 3.1.4 Resource representation

<a id="REPR_JSON"></a>**Rule `REPR_JSON`**: MUST

A Resource Representation MUST be valid JSON ([RFC 8259](https://www.rfc-editor.org/rfc/rfc8259)). Servers SHOULD accept [JSON5](https://spec.json5.org/) input, as [recommended by ECSON](../ecson.md#82-json5-input).

<a id="REPR_ECSON"></a>**Rule `REPR_ECSON`**: SHOULD

Resources SHOULD be represented in [ECSON](https://github.com/lingodata/ecson) (`application/vnd.ecson+json`), to preserve types between Client and Server.

<a id="REPR_ECSON_CUSTOM_TYPES"></a>**Rule `REPR_ECSON_CUSTOM_TYPES`**: MAY

Servers MAY use application-defined ECSON types, following the [ECSON tag namespace rules](../ecson.md#6-tag-ownership-and-namespaces).

Resources are made of values of the types defined by ECSON (dates, big integers, references and others). ECSON is how those values travel without loss; it is not how they are stored ([ECSON section 5.2](../ecson.md#52-processing-limits)).

<a id="REPR_PLAIN_JSON"></a>**Rule `REPR_PLAIN_JSON`**: MUST

When the negotiated Resource Representation is plain JSON, the Server MUST send values in their plain JSON form ([ECSON section 5.3](../ecson.md#53-plain-json-form)) and MUST read request bodies as plain JSON ([ECSON `PLAIN_FORM_READ`](../ecson.md#PLAIN_FORM_READ)).

<a id="REPR_NO_CONVERSION"></a>**Rule `REPR_NO_CONVERSION`**: MUST NOT

The Server MUST NOT convert values read as plain JSON to other types, unless an extension defines the conversion (for example, the [Schema extension](./schema.md#1-schemas)).

<a id="REPR_NATIVE_STORAGE"></a>**Rule `REPR_NATIVE_STORAGE`**: MUST

Providers MUST store values in the native types of the Data source, and MUST NOT store their ECSON serialization.

<a id="REPR_DOWNGRADE"></a>**Rule `REPR_DOWNGRADE`**: MUST

When the Data source has no native type for a value, the Provider MUST store its plain JSON form, and the Server MUST report the [`TYPE_DOWNGRADED`](#TYPE_DOWNGRADED) Warning, with the `field`.

> **Tip (non-normative): Example**
>
> A date is stored as a `Date` in MongoDB, a `timestamptz` in PostgreSQL, a `DATETIME` in MySQL and a date property in Notion or a date field in Airtable. A `$set` sent to a Notion number property has no native equivalent: it is stored in its plain JSON form, with the [`TYPE_DOWNGRADED`](#TYPE_DOWNGRADED) Warning.

<a id="REPR_NO_ENVELOPES"></a>**Rule `REPR_NO_ENVELOPES`**: MUST

Resources MUST NOT be wrapped in envelopes such as `data`, `result`, `response`, or similar constructs. Operation Inputs and Outputs MUST always directly reflect Resources, optional Parameters (as defined by the Protocol), or errors.

### 3.2 Search queries

#### 3.2.1 Definition and representation

A "**Search Query**" is a filter that selects Resources in some operations, written in a format negotiated between Client and Server.

<a id="SEARCH_QUERY_UNQUERY"></a>**Rule `SEARCH_QUERY_UNQUERY`**: SHOULD

Servers SHOULD support Search Queries in the [UnQuery](https://github.com/lingodata/unquery) format, in both its JSON (`application/vnd.unquery+json`) and SQL (`text/vnd.unquery.sql`) syntaxes.

<a id="SEARCH_QUERY_FORMATS"></a>**Rule `SEARCH_QUERY_FORMATS`**: MAY

Servers MAY support other Search Query formats, such as the native query language of a Data source, identified by media types and negotiated as specified in [section 3.4.1](#341-content-negotiation).

> **Caution (non-normative): Native query languages**
>
> A Server that accepts the native query language of its Data source ties its Clients to that Data source and must protect it against injection itself. UnQuery avoids both by translating filters instead of passing text to the Data source.

> **Note (non-normative): Rationale**
>
> UnQuery is recommended, not required, so that Servers can adopt the Base Specification with other query formats.

> **Note (non-normative)**
>
> Saved queries (Views) are defined by the Views extension.

### 3.3 Parameters

This section defines Parameters that apply to several operations. Parameters specific to one operation are defined in [section 4](#4-operation-rules). Each Protocol defines how Parameters are sent.

#### 3.3.1 Field lists

Projection and sorting Parameters take a **field list**: an ordered list of field paths, each with a modifier (omit, for projection; descending, for sorting).

<a id="FIELD_LIST_PATHS"></a>**Rule `FIELD_LIST_PATHS`**: MUST

Each item of a field list MUST be a field path as defined by [UnQuery](https://github.com/lingodata/unquery) ([`PATH_DOT_NOTATION`](../unquery.md#PATH_DOT_NOTATION)), so that nested Fields use dot notation and names with special characters are quoted.

<a id="FIELD_LIST_NO_INDEX"></a>**Rule `FIELD_LIST_NO_INDEX`**: MUST

This specification does not define array indexes ([UnQuery `PATH_INDEX`](../unquery.md#PATH_INDEX)) in field lists. The Server MUST fail with the [`INVALID_INPUT`](#INVALID_INPUT) error for a field list with an item that has an index.

<a id="FIELD_LIST_TEXT"></a>**Rule `FIELD_LIST_TEXT`**: MUST

When a field list is written as text, items MUST be separated by `,` and the modifier MUST be a `-` before the path; segments that contain `,` or start with `-` MUST be quoted. Protocols MAY use other forms, such as JSON arrays, with the same meaning.

> **Tip (non-normative): Example**
>
> `name,-"Total.value",address.city` lists `name`, `Total.value` (with the modifier) and `city` inside `address`.

#### 3.3.2 Projection parameter

A "**Projection Parameter**" selects which Fields are returned in the Result.

<a id="PROJECTION_FIELD_LIST"></a>**Rule `PROJECTION_FIELD_LIST`**: MUST

A Projection Parameter MUST be a field list, where the `-` modifier omits a Field.

<a id="PROJECTION_INCLUDE_DEFAULT"></a>**Rule `PROJECTION_INCLUDE_DEFAULT`**: MUST

When a Projection Parameter has no omitted Fields, only the listed Fields MUST be returned.

<a id="PROJECTION_EXCLUDE"></a>**Rule `PROJECTION_EXCLUDE`**: MUST

When a Projection Parameter has only omitted Fields, every other Field MUST be returned.

<a id="PROJECTION_HYPHEN_OMITS"></a>**Rule `PROJECTION_HYPHEN_OMITS`**: MUST

When a Projection Parameter has both listed and omitted Fields, the Server MUST first select the listed Fields and then remove the omitted ones.

<a id="PROJECTION_ID"></a>**Rule `PROJECTION_ID`**: MUST

The Resource ID MUST always be returned, unless the Projection Parameter omits it explicitly (for example `-_id`).

> **Tip (non-normative): Example**
>
> | Projection | Returned Fields |
> |---|---|
> | `name,address` | `_id`, `name`, `address` |
> | `-password` | every Field except `password` |
> | `address,-address.zip` | `_id` and `address` without `zip` |
> | `name,-_id` | `name` only |

#### 3.3.3 Custom parameters

A "**Custom Parameter**" is a Parameter defined by a Server and not by this specification.

<a id="PARAM_CUSTOM_DECLARE"></a>**Rule `PARAM_CUSTOM_DECLARE`**: SHOULD

A Server SHOULD declare the Custom Parameters it accepts and the operations they apply to.

<a id="PARAM_CUSTOM_UNKNOWN"></a>**Rule `PARAM_CUSTOM_UNKNOWN`**: MUST

When a Client sends a Parameter that the Server does not recognize, the Server MUST ignore it and report the [`PARAM_IGNORED`](#PARAM_IGNORED) Warning. If the Client asked for Warnings to be treated as errors ([`META_WARN_PREFERENCE`](#META_WARN_PREFERENCE)), the operation MUST fail.

> **Note (non-normative): Rationale**
>
> Failing on every unknown Parameter would break Clients whenever a Server removes a Custom Parameter; ignoring them silently would hide typos. Reporting them as Warnings keeps operations working and lets strict Clients opt in to failures.

### 3.4 Metadata

Operation "**Metadata**" is data exchanged between Client and Server about the operation itself: content negotiation, specification versions, counts, correlation and warnings. Each Protocol defines how Metadata is carried (for example, HTTP headers or the MCP `_meta` object).

#### 3.4.1 Content negotiation

"**Content negotiation**" is the exchange of Metadata in which Client and Server agree on the formats of the Input and the Output: the Resource Representation and the Search Query format.

<a id="META_RES_PREFERENCE"></a>**Rule `META_RES_PREFERENCE`**: SHOULD

The Client SHOULD declare the Resource Representations and Search Query formats it accepts. The Server MUST either use one of them or fail the operation with the [`NEGOTIATION`](#NEGOTIATION) error.

<a id="META_RES_FALLBACK"></a>**Rule `META_RES_FALLBACK`**: MUST

When the Client declares no Resource Representation, the Server MUST respond in ECSON if it supports ECSON, and in JSON otherwise. When the Client declares no Search Query format, the Server MUST interpret Search Queries as UnQuery if it supports UnQuery.

<a id="META_RES_TIE"></a>**Rule `META_RES_TIE`**: MUST

When the Client accepts both ECSON and plain JSON with the same preference, including a declaration that accepts any format, the Server MUST respond in ECSON if it supports ECSON. The Server MUST respond in plain JSON only when the Client does not accept ECSON, or prefers plain JSON to ECSON.

> **Note (non-normative): Rationale**
>
> ECSON is the default because it keeps every value exact, and it is still valid JSON: a Client that does not know ECSON can parse the response and sees typed values as small objects, such as `{ "$date": "..." }`. A Client that needs plain values says so explicitly, by not accepting ECSON or by preferring plain JSON.

> **Caution (non-normative)**
>
> The Resource Representation of the Output and that of the Input are chosen separately. Accepting ECSON in the Output does not make the Server read the Input as ECSON: each Protocol labels the Input format (for example, the HTTP `Content-Type` header field), and an Input labeled as plain JSON is read as plain JSON ([`REPR_PLAIN_JSON`](#REPR_PLAIN_JSON)).

<a id="META_PREFER_REPRESENTATION"></a>**Rule `META_PREFER_REPRESENTATION`**: MAY

The Client MAY declare a return preference: `representation`, to receive the Resources affected by the operation, or `minimal`, to receive only the operation status.

<a id="META_RES_DEFAULT"></a>**Rule `META_RES_DEFAULT`**: MUST

Without a return preference, the Server MUST behave as if the Client declared `representation`.

<a id="META_PREFER_STATUS"></a>**Rule `META_PREFER_STATUS`**: MUST

With the `minimal` return preference, the Server MUST NOT send Resources when the operation succeeds, and MUST send only the error data ([section 3.4.4](#344-error-handling)) when it fails.

> **Note (non-normative)**
>
> The return preference follows the `return` preference of the HTTP `Prefer` header ([RFC 7240](https://www.rfc-editor.org/rfc/rfc7240)), defined here independently of HTTP. ECSON output is valid JSON, so the fallback to ECSON is readable by JSON-only Clients.

#### 3.4.2 Specification versions

<a id="META_CRUD_SPECS"></a>**Rule `META_CRUD_SPECS`**: MUST

The Server MUST declare the specifications it implements, the Base Specification and each extension, with the versions it supports for each, as [Semantic Versioning](https://semver.org/) versions, for example `base@0.2.0, async@0.1.0`.

<a id="META_CRUD_REQUIRE"></a>**Rule `META_CRUD_REQUIRE`**: MAY

The Client MAY declare the specifications it requires, each with a version range in the syntax of [node-semver ranges](https://github.com/npm/node-semver#ranges), for example `base@^0.2.0, async@~0.1.0`.

<a id="META_CRUD_RANGE_MATCH"></a>**Rule `META_CRUD_RANGE_MATCH`**: MUST

When the Client declares required specifications, the Server MUST select, for each one, the highest version it supports that satisfies the range, and MUST declare the selected versions in the Output. If any required specification is not supported, or no supported version satisfies its range, the operation MUST fail with the [`NEGOTIATION`](#NEGOTIATION) error, listing the supported versions.

> **Tip (non-normative): Example**
>
> A Server supports `base@0.2.0`, `base@0.3.1` and `async@0.1.0`. A Client requiring `base@^0.2.0, async@^0.1.0` gets `base@0.2.0` and `async@0.1.0` (under node-semver, `^0.2.0` means `>=0.2.0 <0.3.0`). A Client requiring `relationships@^0.1.0` gets the [`NEGOTIATION`](#NEGOTIATION) error.

> **Note (non-normative): Rationale**
>
> Each specification has its own version, so the Server declares the specifications it supports, and Clients negotiate versions with ranges only when they need to.

#### 3.4.3 General metadata

<a id="META_MATCHED_COUNT"></a>**Rule `META_MATCHED_COUNT`**: SHOULD

Operations that take a Search Query SHOULD include a "Matched Count" Metadata field with the total number of Resources matched by the Search Query, regardless of pagination.

<a id="META_MODIFIED_COUNT"></a>**Rule `META_MODIFIED_COUNT`**: SHOULD

Write operations SHOULD include a "Modified Count" Metadata field with the number of Resources modified by the operation.

<a id="META_CORRELATION_ID"></a>**Rule `META_CORRELATION_ID`**: SHOULD

The Client SHOULD send a "Correlation ID" Metadata field with a new UUIDv7 in `uuid-hex` format. If the Client sends one, the Server MUST return the same value; otherwise, the Server SHOULD generate one and return it.

> **Note (non-normative)**
>
> The Correlation ID lets Clients, Servers and intermediaries relate logs and traces of the same operation.

#### 3.4.4 Error handling

When an operation fails, the Server reports one of the error codes below. Each Protocol specification maps these codes to its own (for example, HTTP status codes or JSON-RPC error codes), so that Clients handle errors the same way over any Protocol.

| Code | Condition |
|---|---|
| <a id="INVALID_INPUT"></a>`INVALID_INPUT` | The Subject or a Parameter is malformed, such as an invalid Search Query or field list, or combined pagination Parameters |
| <a id="INVALID_PATCH"></a>`INVALID_PATCH` | A patch is malformed or cannot be applied |
| <a id="NOT_FOUND"></a>`NOT_FOUND` | The Resource or Collection does not exist (extensions may add targets, such as `view` or `operation`) |
| <a id="CONFLICT"></a>`CONFLICT` | A Resource ID sent by the Client already exists |
| <a id="EXPECT_MISMATCH"></a>`EXPECT_MISMATCH` | The number of matched Resources differs from the expected count sent by the Client |
| <a id="UPSERT_DENIED"></a>`UPSERT_DENIED` | The Resource does not exist and the Client denied its creation |
| <a id="NEGOTIATION"></a>`NEGOTIATION` | The Server does not accept the requested format, specification version or Resource ID type |
| <a id="UNSUPPORTED"></a>`UNSUPPORTED` | The Server does not implement the requested operation, operator or feature |
| <a id="STRICT_WARNINGS"></a>`STRICT_WARNINGS` | The Client declared the strict preference and the operation produced Warnings |
| <a id="ACCESS_DENIED"></a>`ACCESS_DENIED` | The Client is not allowed to perform the operation |
| <a id="INTERNAL"></a>`INTERNAL` | The Server or the Data source failed |

<a id="RES_ERROR_DATA"></a>**Rule `RES_ERROR_DATA`**: MUST

When an operation fails, the Server MUST send error data in the negotiated representation, with at least the error code from the table above (or from an extension) and a human-readable message (the `detail` member, in a Problem Details object). For [`NOT_FOUND`](#NOT_FOUND), the error data SHOULD also include a `target` with the kind of missing element: `resource` or `collection`, or a target defined by an extension.

<a id="ERROR_PROBLEM_DETAILS"></a>**Rule `ERROR_PROBLEM_DETAILS`**: SHOULD

Error data SHOULD be a Problem Details object ([RFC 9457](https://www.rfc-editor.org/rfc/rfc9457)), with the error code in a `code` member and, for [`NOT_FOUND`](#NOT_FOUND), the target in a `target` member. The `status` member SHOULD be present only when the Protocol has numeric status codes, such as HTTP.

<a id="ERROR_PROTOCOL_MAPPING"></a>**Rule `ERROR_PROTOCOL_MAPPING`**: MUST

Every Protocol specification MUST map each error code of this specification and of the extensions it supports to an error of the Protocol, and MUST carry the error code of this specification in the error data.

<a id="ERROR_EXTENSION_CODES"></a>**Rule `ERROR_EXTENSION_CODES`**: MAY

Extensions MAY define additional error codes, which MUST NOT reuse the codes of this specification.

<a id="ERROR_CUSTOM_CODES"></a>**Rule `ERROR_CUSTOM_CODES`**: MAY

Servers MAY define their own error codes, which MUST be prefixed with a namespace and a `.` (for example `acme.QUOTA_EXCEEDED`).

<a id="RES_ERROR_MORE_DATA"></a>**Rule `RES_ERROR_MORE_DATA`**: MAY

Error data MAY include additional Fields, such as documentation URLs or tracing information.

> **Tip (non-normative): Example**
>
> Over HTTP, a missing Resource is reported with the status `404 Not Found` and the error data `{ "type": "about:blank", "title": "Not Found", "status": 404, "detail": "Order 0190a5f2-... not found", "code": "NOT_FOUND", "target": "resource" }`; over MCP, with a JSON-RPC error whose data carries the same object, without `status`.

> **Note (non-normative): Rationale**
>
> Protocols have their own error codes, but a generic CRUD Client, such as a user interface or an AI agent, needs the same codes regardless of the Protocol. The Base Specification defines the conditions and their codes; each Protocol specification maps them.

#### 3.4.5 Warnings

<a id="META_WARN"></a>**Rule `META_WARN`**: MAY

The Server MAY report Warnings: conditions that do not prevent the operation, such as deprecations, quotas, ignored Parameters or reduced limits. Each Warning MUST have a code and a human-readable message.

<a id="META_WARN_PREFERENCE"></a>**Rule `META_WARN_PREFERENCE`**: MUST

The Client MAY declare a strict preference. When it does, the Server MUST fail any operation that would produce Warnings with the [`STRICT_WARNINGS`](#STRICT_WARNINGS) error, reporting the Warnings in the error data. Without it, Warnings MUST NOT make an operation fail.

<a id="META_WARN_PREFERENCE_EXCEPT"></a>**Rule `META_WARN_PREFERENCE_EXCEPT`**: MAY

The strict preference MAY list Warning codes that remain Warnings. When it does, the Server MUST report Warnings with a listed code without failing, and MUST fail with the [`STRICT_WARNINGS`](#STRICT_WARNINGS) error any operation that would produce a Warning with another code. A Server that does not support the list MUST apply the strict preference to every Warning.

> **Tip (non-normative): Example**
>
> A Client that accepts reduced limits, but no other Warning, declares the strict preference with the list [`LIMIT_REDUCED`](#LIMIT_REDUCED): a [`LIMIT_REDUCED`](#LIMIT_REDUCED) Warning is reported and the operation succeeds, while any other Warning, such as [`SCHEMA_VIOLATION`](./schema.md#SCHEMA_VIOLATION), makes it fail.

<a id="WARN_DATA"></a>**Rule `WARN_DATA`**: MAY

Besides the code and the message, a Warning MAY include the members `parameter` (the name of a Parameter), `field` (a field path), `id` (a Resource ID) and `error` (an error code), as specified for each Warning code, and other members, such as documentation URLs.

| Code | Condition | Members |
|---|---|---|
| <a id="PARAM_IGNORED"></a>`PARAM_IGNORED` | A Parameter the Server does not recognize was ignored ([`PARAM_CUSTOM_UNKNOWN`](#PARAM_CUSTOM_UNKNOWN)) | `parameter` |
| <a id="LIMIT_REDUCED"></a>`LIMIT_REDUCED` | The Server reduced the `limit` sent by the Client ([`PAGINATION_LIMIT_MAX`](#PAGINATION_LIMIT_MAX)) | `parameter` |
| <a id="ORDER_NOT_PRESERVED"></a>`ORDER_NOT_PRESERVED` | The Result is not in the order of the Subject ([`RES_DETERMINISTIC_WRITES`](#RES_DETERMINISTIC_WRITES)) | |
| <a id="ID_IGNORED"></a>`ID_IGNORED` | A Resource ID in a replacement Resource was ignored ([`SUB_NO_ID`](#SUB_NO_ID)) | `id` |
| <a id="WRITE_FAILED"></a>`WRITE_FAILED` | A Resource was not written in a partial write ([`WRITE_PARTIAL`](#WRITE_PARTIAL)) | `error`, `id` when known |
| <a id="TYPE_DOWNGRADED"></a>`TYPE_DOWNGRADED` | A value was stored in its plain JSON form ([`REPR_DOWNGRADE`](#REPR_DOWNGRADE)) | `field` |
| <a id="DEPRECATED"></a>`DEPRECATED` | The operation used a Parameter, format or feature that the Server will remove | `parameter` when it applies |

<a id="WARN_STANDARD_CODES"></a>**Rule `WARN_STANDARD_CODES`**: MUST

For the conditions in the table above, the Server MUST use the Warning codes and members of the table.

<a id="WARN_EXTENSION_CODES"></a>**Rule `WARN_EXTENSION_CODES`**: MAY

Extensions and Protocol specifications MAY define additional Warning codes, and MUST NOT reuse the codes of this specification.

<a id="WARN_CUSTOM_CODES"></a>**Rule `WARN_CUSTOM_CODES`**: MAY

Servers MAY define their own Warning codes, which MUST be prefixed with a namespace and a `.` (for example `acme.QUOTA_LOW`).

<a id="WARN_UNKNOWN_CODES"></a>**Rule `WARN_UNKNOWN_CODES`**: MUST

Clients MUST accept Warnings with codes they do not know, and treat them as generic Warnings.

> **Note (non-normative)**
>
> Quotas and other conditions that depend on each Server use custom codes ([`WARN_CUSTOM_CODES`](#WARN_CUSTOM_CODES)). A Client may keep some Warning codes as Warnings while every other code fails ([`META_WARN_PREFERENCE_EXCEPT`](#META_WARN_PREFERENCE_EXCEPT)).

> **Note (non-normative)**
>
> The strict preference follows the `handling=strict` preference of the HTTP `Prefer` header ([RFC 7240](https://www.rfc-editor.org/rfc/rfc7240)).

## 4. Operation rules

### 4.1 Get

#### 4.1.1 Operation `get`

<a id="SUB_ID"></a>**Rule `SUB_ID`**: MUST

Client MUST send a single Resource ID in the Subject.

<a id="RES_RESOURCES_FOUND"></a>**Rule `RES_RESOURCES_FOUND`**: MUST

Server MUST return the Resources matched by the Subject.

<a id="RES_MATCHING_REQUIRED"></a>**Rule `RES_MATCHING_REQUIRED`**: MUST

If no Resource matches the Resource ID, the Server MUST fail the operation with the [`NOT_FOUND`](#NOT_FOUND) error.

<a id="PARAM_PROJECTION"></a>**Rule `PARAM_PROJECTION`**: MAY

Client MAY send a [Projection Parameter](#332-projection-parameter).

### 4.2 List

#### 4.2.1 Operation `list`

<a id="SUB_SEARCH_QUERY"></a>**Rule `SUB_SEARCH_QUERY`**: MUST

If the Client specifies a Subject, it MUST be a Search Query as defined in [Section 3.2.1 Definition and representation](#321-definition-and-representation). CRUD Participants MUST negotiate the Search Query format as specified in [3.4.1 Content negotiation](#341-content-negotiation).

<a id="SUB_EMPTY"></a>**Rule `SUB_EMPTY`**: MAY

The Client MAY omit the Subject. In this case, every Resource of the Collection matches, subject to pagination.

**See rule [`RES_RESOURCES_FOUND`](#RES_RESOURCES_FOUND)** (MUST, section 4.1.1)

<a id="RES_NO_RESULTS"></a>**Rule `RES_NO_RESULTS`**: MUST

If no Resource matches the Search Query, the Server MUST NOT fail the operation: read operations return an empty list and write operations modify nothing, with a Modified Count of 0.

<a id="PARAM_PAGINATION"></a>**Rule `PARAM_PAGINATION`**: MAY

Client MAY send a [Pagination Parameter](#424-pagination-parameters).

<a id="PARAM_CUSTOM"></a>**Rule `PARAM_CUSTOM`**: MAY

Client MAY send a [Custom Parameter](#425-custom-parameters).

**See rule [`PARAM_PROJECTION`](#PARAM_PROJECTION)** (MAY, section 4.1.1)

<a id="PARAM_SORTING"></a>**Rule `PARAM_SORTING`**: MAY

Client MAY send a [Sorting Parameter](#423-sorting-parameter).

#### 4.2.3 Sorting Parameter

A "**Sorting Parameter**" determines the order of the Results of `list` operations.

<a id="SORTING_FIELD_LIST"></a>**Rule `SORTING_FIELD_LIST`**: MUST

A Sorting Parameter MUST be a field list ([section 3.3.1](#331-field-lists)), where the `-` modifier means descending order and Fields without it are sorted in ascending order. The Server MUST sort by each Field in the order of the list.

<a id="SORTING_NULLS"></a>**Rule `SORTING_NULLS`**: MUST

`null` and missing Fields MUST be sorted as lower than any other value, so they come first in ascending order and last in descending order.

<a id="SORTING_DEFAULT"></a>**Rule `SORTING_DEFAULT`**: SHOULD

Without a Sorting Parameter, the Server SHOULD sort by Resource ID, and it SHOULD add the Resource ID as the last sorting key, so that pages are stable.

> **Note (non-normative)**
>
> The order between values of different types is implementation-defined. With UUIDv7 Resource IDs in `uuid-hex` format ([`ID_UUID`](#ID_UUID)), sorting by Resource ID is equivalent to sorting by creation time. Providers for SQL Data sources implement [`SORTING_NULLS`](#SORTING_NULLS) with `NULLS FIRST` (ascending) and `NULLS LAST` (descending).

#### 4.2.4 Pagination Parameters

"**Pagination Parameters**" split the Results of `list` operations into pages. There are three ways to paginate, all with a `limit`, the maximum number of Resources per page.

| Way | Parameters | Best for |
|---|---|---|
| Page | `page` (starting at 1) and `limit` | screens and charts that jump to a page |
| Offset | `offset` (number of Resources to skip, starting at 0, also called skip) and `limit` | clients that compute positions |
| Cursor | `cursor` (an opaque token returned by the previous page) and `limit` | large Collections, where skipping many Resources is slow |

<a id="PAGINATION_PAGE"></a>**Rule `PAGINATION_PAGE`**: SHOULD

A Server that paginates SHOULD support the `page` and `limit` Parameters.

<a id="PAGINATION_OFFSET"></a>**Rule `PAGINATION_OFFSET`**: MAY

A Server MAY support the `offset` and `limit` Parameters.

<a id="PAGINATION_CURSOR"></a>**Rule `PAGINATION_CURSOR`**: MAY

A Server MAY support cursor pagination. When it does, the Result metadata MUST include the cursor of the next page, or indicate that there is no next page, and the cursor MUST be opaque to the Client.

<a id="PAGINATION_EXCLUSIVE"></a>**Rule `PAGINATION_EXCLUSIVE`**: MUST

`page`, `offset` and `cursor` MUST NOT be combined in the same operation; the Server MUST fail if they are.

<a id="PAGINATION_LIMIT_MAX"></a>**Rule `PAGINATION_LIMIT_MAX`**: MAY

A Server MAY cap `limit` and MAY apply a default `limit` when the Client sends none. When it reduces the `limit` sent by the Client, it MUST report the [`LIMIT_REDUCED`](#LIMIT_REDUCED) Warning.

> **Note (non-normative)**
>
> The total number of matching Resources is reported by [`META_MATCHED_COUNT`](#META_MATCHED_COUNT).

#### 4.2.5 Custom Parameters

Custom Parameters are defined in [section 3.3.3](#333-custom-parameters).

### 4.3 Create

#### 4.3.1 Operation `create`

<a id="SUB_RESOURCES_CREATE"></a>**Rule `SUB_RESOURCES_CREATE`**: MUST

Client MUST send either a single Resource or a list of multiple Resources.

<a id="SUB_WITH_IDS"></a>**Rule `SUB_WITH_IDS`**: MAY

The Client MAY send Resources with Resource IDs, in a type the Server accepts for the Collection.

<a id="RES_RESOURCES_WRITTEN"></a>**Rule `RES_RESOURCES_WRITTEN`**: MUST

Server MUST return the Resource(s) that were the subject of the operation (created, modified, or replaced).

<a id="RES_WITH_IDS"></a>**Rule `RES_WITH_IDS`**: MUST

Resource IDs MUST be returned with their Resources

<a id="RES_NO_IDS"></a>**Rule `RES_NO_IDS`**: MUST

If the Server cannot create Resources with the Resource IDs sent by the Client, the operation MUST fail with the [`NEGOTIATION`](#NEGOTIATION) error.

<a id="RES_CONFLICT"></a>**Rule `RES_CONFLICT`**: MUST

If a Resource ID sent by the Client already exists in the Collection, the Server MUST fail the operation with the [`CONFLICT`](#CONFLICT) error.

<a id="RES_DETERMINISTIC_WRITES"></a>**Rule `RES_DETERMINISTIC_WRITES`**: SHOULD

When the Subject has several Resources, the Server SHOULD return the Result in the same order as the Subject. If it cannot, it MUST report the [`ORDER_NOT_PRESERVED`](#ORDER_NOT_PRESERVED) Warning.

<a id="PARAM_PROJECTION_WRITE"></a>**Rule `PARAM_PROJECTION_WRITE`**: MAY

Client MAY send a Projection Parameter in order to reduce redundancy of Resources returned in the Result.

#### 4.3.2 Operation `clone`

`clone` is a shorthand for creating a copy of an existing Resource with a new Resource ID.

<a id="SUB_CLONE"></a>**Rule `SUB_CLONE`**: MUST

The Client MUST send the Resource ID of the source Resource. The Client MAY also send a patch (as in [`SUB_JSON_PATCH`](#SUB_JSON_PATCH) and [`SUB_MERGE_PATCH`](#SUB_MERGE_PATCH)) to apply to the copy, and MAY send the Resource ID of the copy.

<a id="RES_CLONE"></a>**Rule `RES_CLONE`**: MUST

The Server MUST create a new Resource in the same Collection with the Fields of the source Resource, apply the patch if one was sent, and assign it a new Resource ID (or the one sent by the Client). Reserved Fields defined by extensions follow the rules of each extension.

**See rule [`RES_MATCHING_REQUIRED`](#RES_MATCHING_REQUIRED)** (MUST, section 4.1.1)

**See rule [`RES_RESOURCES_WRITTEN`](#RES_RESOURCES_WRITTEN)** (MUST, section 4.3.1)

**See rule [`RES_CONFLICT`](#RES_CONFLICT)** (MUST, section 4.3.1)

**See rule [`PARAM_PROJECTION_WRITE`](#PARAM_PROJECTION_WRITE)** (MAY, section 4.3.1)

> **Note (non-normative)**
>
> Without `clone`, a Client would need a `get` followed by a `create`, which is two round trips and can copy a stale version. The Metadata extension records the source Resource as the ancestor of the copy.

### 4.4 Patch

#### 4.4.1 Operation `patchById`

**See rule [`SUB_ID`](#SUB_ID)** (MUST, section 4.1.1)

<a id="SUB_JSON_PATCH"></a>**Rule `SUB_JSON_PATCH`**: MUST

The Client MUST send the patch as a JSON Patch ([RFC 6902](https://www.rfc-editor.org/rfc/rfc6902)) document. If the patch is malformed or cannot be applied, the Server MUST fail the operation with the [`INVALID_PATCH`](#INVALID_PATCH) error.

<a id="SUB_MERGE_PATCH"></a>**Rule `SUB_MERGE_PATCH`**: MAY

The Server MAY also accept the patch as a JSON Merge Patch ([RFC 7396](https://www.rfc-editor.org/rfc/rfc7396)) document, negotiated with the `application/merge-patch+json` media type.

> **Note (non-normative)**
>
> A JSON Merge Patch is a partial Resource with the new values, for example `{ "name": "Ana", "nickname": null }`. In a Merge Patch, `null` removes the Field, so a Field cannot be set to `null`; a JSON Patch with a `replace` operation can.

**See rule [`RES_RESOURCES_WRITTEN`](#RES_RESOURCES_WRITTEN)** (MUST, section 4.3.1)

**See rule [`RES_MATCHING_REQUIRED`](#RES_MATCHING_REQUIRED)** (MUST, section 4.1.1)

**See rule [`PARAM_PROJECTION_WRITE`](#PARAM_PROJECTION_WRITE)** (MAY, section 4.3.1)


#### 4.4.2 Operation `patchByQuery`

<a id="SUB_SEARCH_QUERY_WRITE"></a>**Rule `SUB_SEARCH_QUERY_WRITE`**: MUST

Client MUST send a Search Query as defined in [Section 3.2.1 Definition and representation](#321-definition-and-representation) in the Subject. CRUD Participants MUST negotiate the Search Query format as specified in [3.4.1 Content negotiation](#341-content-negotiation).

**See rule [`SUB_JSON_PATCH`](#SUB_JSON_PATCH)** (MUST, section 4.4.1)

**See rule [`SUB_MERGE_PATCH`](#SUB_MERGE_PATCH)** (MAY, section 4.4.1)

**See rule [`RES_RESOURCES_WRITTEN`](#RES_RESOURCES_WRITTEN)** (MUST, section 4.3.1)

**See rule [`RES_NO_RESULTS`](#RES_NO_RESULTS)** (MUST, section 4.2.1)

**See rule [`PARAM_PROJECTION_WRITE`](#PARAM_PROJECTION_WRITE)** (MAY, section 4.3.1)

<a id="PARAM_EXPECT_MATCH"></a>**Rule `PARAM_EXPECT_MATCH`**: MAY

The Client MAY send an "Expect Match" Parameter with the number of Resources the Search Query is expected to match. The Server MUST check it before writing anything and, if the matched count differs, MUST fail the operation with the [`EXPECT_MISMATCH`](#EXPECT_MISMATCH) error without modifying any Resource.

### 4.5 Replace

#### 4.5.1 Operation `replaceById`

<a id="SUB_ID_REPLACE"></a>**Rule `SUB_ID_REPLACE`**: MUST

The Subject MUST contain the Resource ID of the Resource to replace, inside the replacement Resource or separately. If both are present and differ, the Server MUST fail the operation with the [`INVALID_INPUT`](#INVALID_INPUT) error.

<a id="SUB_RESOURCE_REPLACE"></a>**Rule `SUB_RESOURCE_REPLACE`**: MUST

Client MUST send a new Resource to replace the original Resource(s) matched

**See rule [`RES_RESOURCES_WRITTEN`](#RES_RESOURCES_WRITTEN)** (MUST, section 4.3.1)

<a id="RES_UPSERT_PREVENTED"></a>**Rule `RES_UPSERT_PREVENTED`**: MUST

If no Resource has the Resource ID and the Client denied upserts ([`PARAM_DENY_UPSERT`](#PARAM_DENY_UPSERT)), the Server MUST fail the operation with the [`UPSERT_DENIED`](#UPSERT_DENIED) error.

**See rule [`PARAM_PROJECTION_WRITE`](#PARAM_PROJECTION_WRITE)** (MAY, section 4.3.1)

<a id="PARAM_DENY_UPSERT"></a>**Rule `PARAM_DENY_UPSERT`**: MAY

Client MAY send a “Deny Upsert” Parameter to explicitly indicate that the Server MUST NOT create a new Resource if the Resource ID is not found in the Collection.

<a id="META_UPSERTED"></a>**Rule `META_UPSERTED`**: MUST

If the Resource ID is not found during the operation and the Server creates the Resource, the Server MUST send an “Upserted” Metadata indicating the Resource was created instead of replaced.

#### 4.5.2 Operation `replaceByQuery`

**See rule [`SUB_SEARCH_QUERY_WRITE`](#SUB_SEARCH_QUERY_WRITE)** (MUST, section 4.4.2)

**See rule [`SUB_RESOURCE_REPLACE`](#SUB_RESOURCE_REPLACE)** (MUST, section 4.5.1)

<a id="REPLACE_QUERY_EACH"></a>**Rule `REPLACE_QUERY_EACH`**: MUST

The Server MUST replace each Resource matched by the Search Query with the replacement Resource, keeping the Resource ID of each one, and MUST NOT create Resources (no upsert).

<a id="SUB_NO_ID"></a>**Rule `SUB_NO_ID`**: SHOULD

The replacement Resource SHOULD NOT include a Resource ID. If it does, the Server MUST ignore it, keep the Resource ID of each matched Resource, and report the [`ID_IGNORED`](#ID_IGNORED) Warning.

**See rule [`RES_RESOURCES_WRITTEN`](#RES_RESOURCES_WRITTEN)** (MUST, section 4.3.1)

**See rule [`RES_NO_RESULTS`](#RES_NO_RESULTS)** (MUST, section 4.2.1)

**See rule [`PARAM_PROJECTION_WRITE`](#PARAM_PROJECTION_WRITE)** (MAY, section 4.3.1)

**See rule [`PARAM_EXPECT_MATCH`](#PARAM_EXPECT_MATCH)** (MAY, section 4.4.2)

> **Tip (non-normative)**
>
> To replace exactly one Resource found by a Search Query, send an "Expect Match" Parameter of `1`: the Server fails with [`EXPECT_MISMATCH`](#EXPECT_MISMATCH), without writing, if the Search Query matches any other number of Resources.

### 4.6 Delete

#### 4.6.1 Operation `deleteById`

**See rule [`SUB_ID`](#SUB_ID)** (MUST, section 4.1.1)

<a id="RES_EMPTY"></a>**Rule `RES_EMPTY`**: MUST

Delete operations MUST behave as if the Client declared the `minimal` return preference when it declares none: the Server returns no Resources. When the Client declares `representation`, the Server MUST return the deleted Resources.

**See rule [`RES_MATCHING_REQUIRED`](#RES_MATCHING_REQUIRED)** (MUST, section 4.1.1)

#### 4.6.2 Operation `deleteByQuery`

**See rule [`SUB_SEARCH_QUERY_WRITE`](#SUB_SEARCH_QUERY_WRITE)** (MUST, section 4.4.2)

**See rule [`RES_EMPTY`](#RES_EMPTY)** (MUST, section 4.6.1)

**See rule [`RES_NO_RESULTS`](#RES_NO_RESULTS)** (MUST, section 4.2.1)

**See rule [`PARAM_EXPECT_MATCH`](#PARAM_EXPECT_MATCH)** (MAY, section 4.4.2)

### 4.7 Writes on several Resources

A write operation may affect several Resources: `create` with a list, and the `ByQuery` operations. This section defines what happens when some of them fail.

<a id="WRITE_MODIFIED_COUNT"></a>**Rule `WRITE_MODIFIED_COUNT`**: MUST

A write operation on several Resources MUST always report the Modified Count ([`META_MODIFIED_COUNT`](#META_MODIFIED_COUNT)), whether it succeeds or fails.

<a id="WRITE_ATOMIC_STRICT"></a>**Rule `WRITE_ATOMIC_STRICT`**: MUST

When the Client declared the strict preference ([`META_WARN_PREFERENCE`](#META_WARN_PREFERENCE)), a write operation on several Resources MUST be atomic: either every Resource is written or none is. A Server that cannot guarantee atomicity for the Collection MUST fail with the [`UNSUPPORTED`](#UNSUPPORTED) error before writing anything.

<a id="WRITE_ATOMIC_TRANSACTIONAL"></a>**Rule `WRITE_ATOMIC_TRANSACTIONAL`**: MUST

When the Data source supports transactions, a write operation on several Resources MUST be atomic: if any Resource cannot be written, the operation MUST fail and no Resource is written.

<a id="WRITE_PARTIAL"></a>**Rule `WRITE_PARTIAL`**: MAY

Otherwise, a write operation on several Resources MAY be partial: the Server writes the Resources it can, returns them in the Result, and reports each Resource it could not write as a [`WRITE_FAILED`](#WRITE_FAILED) Warning, with the error code and, when known, the Resource ID.

<a id="WRITE_ATOMICITY_DECLARE"></a>**Rule `WRITE_ATOMICITY_DECLARE`**: SHOULD

A Server SHOULD declare, for each Collection, whether writes on several Resources are atomic.

| Data source | Strict preference | Behavior |
|---|---|---|
| Transactional (PostgreSQL) | any | atomic: any failure fails the operation, nothing is written |
| Not transactional (Notion, Airtable) | strict | [`UNSUPPORTED`](#UNSUPPORTED), nothing is written |
| Not transactional (Notion, Airtable) | not strict | partial: written Resources in the Result, failures as Warnings |

> **Note (non-normative): Rationale**
>
> Partial failures follow the same model as other Warnings: Clients that need all-or-nothing behavior declare the strict preference, which turns any Warning into an error, and therefore requires a transaction.

## 5. Origins and references

### 5.1 Origins

This specification grew out of years of building CRUD APIs over different data sources. Its rules consolidate patterns from:

- **Existing standards**: [HTTP semantics](https://www.rfc-editor.org/rfc/rfc9110), the [`Prefer` header](https://www.rfc-editor.org/rfc/rfc7240), [JSON Patch](https://www.rfc-editor.org/rfc/rfc6902), [Web Linking](https://www.rfc-editor.org/rfc/rfc8288) and [UUIDs](https://www.rfc-editor.org/rfc/rfc9562) (see 5.2).
- **API conventions**: [JSON:API](https://jsonapi.org/format/), [OData](https://www.odata.org/documentation/) and the [REST architectural style](https://ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm).
- **Public APIs**: [Salesforce](https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_rest.htm), [GitHub](https://docs.github.com/en/rest), [Notion](https://developers.notion.com/reference/intro) and [WordPress](https://developer.wordpress.org/rest-api/), whose parameters, endpoint structures and response conventions informed the operations and parameters.
- **Data formats**: [MongoDB Extended JSON](https://www.mongodb.com/docs/manual/reference/mongodb-extended-json/) and [Meteor EJSON](https://docs.meteor.com/api/ejson.html), whose limitations led to [ECSON](https://github.com/lingodata/ecson).

### 5.2 Normative references

- [RFC 2119](https://www.rfc-editor.org/rfc/rfc2119) and [RFC 8174](https://www.rfc-editor.org/rfc/rfc8174): requirement level key words (BCP 14)
- [RFC 4648](https://www.rfc-editor.org/rfc/rfc4648): The Base16, Base32, and Base64 Data Encodings
- [RFC 6902](https://www.rfc-editor.org/rfc/rfc6902): JavaScript Object Notation (JSON) Patch
- [RFC 7396](https://www.rfc-editor.org/rfc/rfc7396): JSON Merge Patch
- [RFC 8259](https://www.rfc-editor.org/rfc/rfc8259): The JavaScript Object Notation (JSON) Data Interchange Format
- [RFC 9562](https://www.rfc-editor.org/rfc/rfc9562): Universally Unique IDentifiers (UUIDs)
- [RFC 9457](https://www.rfc-editor.org/rfc/rfc9457): Problem Details for HTTP APIs
- [Semantic Versioning 2.0.0](https://semver.org/)
- [node-semver ranges](https://github.com/npm/node-semver#ranges): version range syntax used in specification negotiation
- [ECSON](https://github.com/lingodata/ecson): ECMAScript Object Notation (LingoData)
- [UnQuery](https://github.com/lingodata/unquery): Universal Query String Filter Specification (LingoData)

### 5.3 Informative references

- [RFC 9110](https://www.rfc-editor.org/rfc/rfc9110): HTTP Semantics
- [RFC 5789](https://www.rfc-editor.org/rfc/rfc5789): PATCH Method for HTTP
- [RFC 7240](https://www.rfc-editor.org/rfc/rfc7240): Prefer Header for HTTP
- [RFC 8288](https://www.rfc-editor.org/rfc/rfc8288): Web Linking
- [JSON:API](https://jsonapi.org/format/)
- [OData](https://www.odata.org/documentation/)
- [MongoDB Extended JSON](https://www.mongodb.com/docs/manual/reference/mongodb-extended-json/)
- [Meteor EJSON](https://docs.meteor.com/api/ejson.html)
- [JSON5](https://spec.json5.org/)

### 5.4 References used by the extensions

| Reference | Used by |
|---|---|
| [Standard Webhooks](https://www.standardwebhooks.com/) | Asynchronous operations: signing and delivery of callbacks |
| [RFC 3986](https://www.rfc-editor.org/rfc/rfc3986): URI Generic Syntax | Relationships: URI references (through ECSON `$rel`) |
| [RFC 8288](https://www.rfc-editor.org/rfc/rfc8288): Web Linking | Relationships: Link header references (through ECSON `$rel`) |
| [RFC 9264](https://www.rfc-editor.org/rfc/rfc9264): Linkset | Relationships: link objects (through ECSON `$rel`) |
| [IANA Link Relations](https://www.iana.org/assignments/link-relations/link-relations.xhtml) | Relationships: registered relation types |
| [RFC 8785](https://www.rfc-editor.org/rfc/rfc8785): JSON Canonicalization Scheme (JCS) | Metadata: content hash (through ECSON canonical mode) |

> **Note (non-normative)**
>
> Protocol-specific references (HTTP status codes and headers, JSON-RPC and MCP) belong to each Protocol specification.
