|
| 1 | +# Local Identities Extension |
| 2 | + |
| 3 | +This extension provides a means to uniquely identify resources "local" to a |
| 4 | +specific document. |
| 5 | + |
| 6 | +Resources can be assigned a "local identity" that can be used to reference each |
| 7 | +other before they have been assigned a permanent `id`. |
| 8 | + |
| 9 | +## <a href="#namespace" id="namespace" class="headerlink"></a> Namespace |
| 10 | + |
| 11 | +This extension uses the namespace `local`. |
| 12 | + |
| 13 | +> Note: JSON:API extensions can only introduce new document members using a |
| 14 | +> reserved namespace as a prefix. |
| 15 | +
|
| 16 | +## <a href="#document-structure" id="document-structure" class="headerlink"></a> Document Structure |
| 17 | + |
| 18 | +A document that supports this extension **MAY** include "local identity" members |
| 19 | +using the `local:id` key in the root of resource objects and resource identity |
| 20 | +objects. The values of these members uniquely identify resources within the |
| 21 | +document. |
| 22 | + |
| 23 | +Local identity members **MUST NOT** co-exist with `id` members. |
| 24 | + |
| 25 | +Local identity values **MUST** be strings that are unique across resource types. |
| 26 | +Different resources of different types **MUST NOT** contain identical local |
| 27 | +identity values in a document. |
| 28 | + |
| 29 | +## <a href="#processing" id="processing" class="headerlink"></a> Processing |
| 30 | + |
| 31 | +Clients **MAY** include local identity (`local:id`) members in resources and |
| 32 | +resource identifier objects in order to uniquely identify resources that have |
| 33 | +not yet been assigned `id` members. |
| 34 | + |
| 35 | +For example, the following POST request contains a resource that references |
| 36 | +itself in a relationship: |
| 37 | + |
| 38 | +```json |
| 39 | +POST /people HTTP/1.1 |
| 40 | +Content-Type: application/vnd.api+json;ext="https://jsonapi.org/ext/local" |
| 41 | +Accept: application/vnd.api+json;ext="https://jsonapi.org/ext/local" |
| 42 | + |
| 43 | +{ |
| 44 | + "data": { |
| 45 | + "local:id": "a", |
| 46 | + "type": "people", |
| 47 | + "attributes": { |
| 48 | + "firstName": "John", |
| 49 | + "lastName": "Doe" |
| 50 | + }, |
| 51 | + "relationships": { |
| 52 | + "bestFriend": { |
| 53 | + "data": { |
| 54 | + "local:id": "a", |
| 55 | + "type": "people" |
| 56 | + } |
| 57 | + } |
| 58 | + } |
| 59 | + } |
| 60 | +} |
| 61 | +``` |
| 62 | + |
| 63 | +Servers that receive a request with this extension applied **MUST** inspect |
| 64 | +all resource objects and resource identifier objects in the request document. |
| 65 | +If the objects do not contain `id` members, the server **MUST** check for |
| 66 | +`local:id` members. If present, these local identities **MUST** be used to |
| 67 | +uniquely identify resources when processing the request. |
| 68 | + |
| 69 | +The server **MUST NOT** include `local:id` members in a response document. |
| 70 | + |
| 71 | +For example, the following response would be appropriate for the previous |
| 72 | +request: |
| 73 | + |
| 74 | +```json |
| 75 | +HTTP/1.1 201 Created |
| 76 | +Location: http://example.com/people/550e8400-e29b-41d4-a716-446655440000 |
| 77 | +Content-Type: application/vnd.api+json;ext="https://jsonapi.org/ext/local" |
| 78 | + |
| 79 | +{ |
| 80 | + "data": { |
| 81 | + "id": "550e8400-e29b-41d4-a716-446655440000", |
| 82 | + "type": "people", |
| 83 | + "attributes": { |
| 84 | + "firstName": "John", |
| 85 | + "lastName": "Doe" |
| 86 | + }, |
| 87 | + "relationships": { |
| 88 | + "bestFriend": { |
| 89 | + "data": { |
| 90 | + "id": "550e8400-e29b-41d4-a716-446655440000", |
| 91 | + "type": "people" |
| 92 | + } |
| 93 | + } |
| 94 | + } |
| 95 | + } |
| 96 | +} |
| 97 | +``` |
0 commit comments