Updates message/foreign-key-relations.md

Auto commit by GitBook Editor
This commit is contained in:
apidesigner
2017-02-14 17:09:53 +00:00
parent 501adf377c
commit 973b9d76ef
2 changed files with 67 additions and 0 deletions

View File

@@ -25,6 +25,7 @@
* [Content Negotiation](message/content-negotiation.md)
* [HAL](message/hal.md)
* [Problem Detail](message/error-reporting.md)
* [Foreign Key Relations](message/foreign-key-relations.md)
* [Application](application/README.md)
* [Evolution](evolution/README.md)
* [Naming Conventions](evolution/naming-conventions.md)

View File

@@ -0,0 +1,66 @@
# Foreign Key Relations
## Link or Embed Foreign Key Relation
When a resource representation includes relation with another (foreign) resource the relation **MUST** be expressed as a link relation or embed the related resource.
#### Example
Use e.g.:
```json
{
"_links": {
"author": { "href": "/users/john" }
...
}
...
}
```
or e.g.:
```json
{
...
"_embedded": {
"author": {
"_links": { "self": "/users/john" },
"name": "John Appleseed",
"email": "john@apple.com"
}
}
}
```
instead e.g.:
```json
{
...
"author_href": "/users/john"
}
```
## Nest Foreign Key Relation
If a foreign object has another identifier but URI or the foreign object isn't a resource the object **MUST** be nested.
#### Example
Use e.g.:
```json
{
"author": {
"id": "1234",
"name": "John Appleseed",
"email": "john@apple.com"
}
}
```
instead e.g.:
```json
{
"author_id": "1234"
}
```