Skip to content

Commit eedd85c

Browse files
committed
Introduce Local IDs to v1.1
A client may include a "local ID" as a `lid` member in a resource object to uniquely identify the resource within the request document. Every representation of that resource, whether as a resource object or resource identifier object, must then include the matching `lid` member and value. When a server receives a request document that contains resources with local IDs, the server must include the matching `lid` member and value in every representation of that resource or resource identifier in the response document. This addition paves the way for requests of all kinds that may need to establish linkage between resources that have not yet been assigned a server-generated ID.
1 parent 0342e46 commit eedd85c

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

_format/1.1/index.md

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ In addition, a resource object **MAY** contain any of these top-level members:
164164
* `links`: a [links object][links] containing links related to the resource.
165165
* `meta`: a [meta object][meta] containing non-standard meta-information about a
166166
resource that can not be represented as an attribute or relationship.
167+
* `lid`: a local identifier that, together with `type`, uniquely
168+
identifies a resource within the document.
167169

168170
Here's how an article (i.e. a resource of type "articles") might appear in a document:
169171

@@ -190,8 +192,18 @@ Here's how an article (i.e. a resource of type "articles") might appear in a doc
190192

191193
#### <a href="#document-resource-object-identification" id="document-resource-object-identification" class="headerlink"></a> Identification
192194

193-
Every [resource object][resource objects] **MUST** contain an `id` member and a `type` member.
194-
The values of the `id` and `type` members **MUST** be strings.
195+
As noted above, every [resource object][resource objects] **MUST** contain a
196+
`type` member. Every resource object **MUST** also contain an `id` member,
197+
except when the resource object originates at the client and represents a new
198+
resource to be created on the server. The values of the `id` and `type` members
199+
**MUST** be strings.
200+
201+
A [resource object][resource objects] **MAY** contain a `lid` member that,
202+
together with `type`, uniquely identifies the resource _locally_ within the
203+
document. If a [resource object][resource objects] contains a `lid` member, then
204+
every representation of that resource, including other [resource objects] and
205+
[resource identifier objects], **MUST** also contain the `lid` member with the
206+
same value. The value of the `lid` member **MUST** be a string.
195207

196208
Within a given API, each resource object's `type` and `id` pair **MUST**
197209
identify a single, unique resource. (The set of URIs controlled by a server,
@@ -360,10 +372,21 @@ response that includes the resource as the primary data.
360372
A "resource identifier object" is an object that identifies an individual
361373
resource.
362374

363-
A "resource identifier object" **MUST** contain `type` and `id` members.
375+
A "resource identifier object" **MUST** contain a `type` member. A resource
376+
identifier object **MUST** also contain an `id` member, except when it contains
377+
a `lid` that identifies it as matching a new resource to be created on the
378+
server.
379+
380+
A "resource identifier object" **MAY** contain a `lid` member. If `id` is
381+
omitted due to the exception described above, a `lid` member **MUST** be
382+
included. A `lid` member **MUST** also be included if the referenced resource is
383+
represented elsewhere in the document with a `lid`. The value of a `lid` member
384+
**MUST** be identical for every representation of the resource in the document.
385+
386+
The values of the `id`, `lid`, and `type` members **MUST** be strings.
364387

365-
A "resource identifier object" **MAY** also include a `meta` member, whose value is a [meta] object that
366-
contains non-standard meta-information.
388+
A "resource identifier object" **MAY** also include a `meta` member, whose value
389+
is a [meta] object that contains non-standard meta-information.
367390

368391
### <a href="#document-compound-documents" id="document-compound-documents" class="headerlink"></a> Compound Documents
369392

@@ -470,6 +493,11 @@ each `type` and `id` pair.
470493
composite key that uniquely references [resource objects] in another part of
471494
the document.
472495

496+
> Note: For resources that do not contain an `id` member but do contain a `lid`,
497+
the `type` and `lid` are sufficient to establish resource identity and thus
498+
linkage between resource objects and resource identifier objects throughout the
499+
document.
500+
473501
> Note: This approach ensures that a single canonical [resource object][resource objects] is
474502
returned with each response, even when the same resource is referenced
475503
multiple times.
@@ -510,7 +538,7 @@ Each member of a links object is a "link". A link **MUST** be represented as
510538
either:
511539

512540
* a string containing the link's URL.
513-
* <a id="document-links-link-object"></a>an object ("link object") which can
541+
* <a id="document-links-link-object"></a>an object ("link object") which can
514542
contain the following members:
515543
* `href`: a string containing the link's URL.
516544
* `meta`: a meta object containing non-standard meta-information about the
@@ -1156,6 +1184,11 @@ also allow existing resources to be modified or deleted.
11561184
A request **MUST** completely succeed or fail (in a single "transaction"). No
11571185
partial updates are allowed.
11581186

1187+
If a [resource object][resource objects] or [resource identifier object] in a
1188+
request document includes a `lid` member, then the server **MUST** include the
1189+
matching `lid` member and value in every representation of that resource or
1190+
resource identifier in the response document.
1191+
11591192
> Note: The `type` member is required in every [resource object][resource objects] throughout requests and
11601193
responses in JSON API. There are some cases, such as when `POST`ing to an
11611194
endpoint representing heterogenous data, when the `type` could not be inferred

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy