mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Add output examples to Adapters docs
This commit is contained in:
parent
e1d1a3dbf9
commit
bfff46b66e
@ -35,6 +35,7 @@ Fixes:
|
||||
- [#1488](https://github.com/rails-api/active_model_serializers/pull/1488) Require ActiveSupport's string inflections (@nate00)
|
||||
|
||||
Misc:
|
||||
- [#1602](https://github.com/rails-api/active_model_serializers/pull/1602) Add output examples to Adapters docs (@remear)
|
||||
- [#1557](https://github.com/rails-api/active_model_serializers/pull/1557) Update docs regarding overriding the root key (@Jwan622)
|
||||
- [#1471](https://github.com/rails-api/active_model_serializers/pull/1471) [Cleanup] Serializer caching is its own concern. (@bf4)
|
||||
- [#1482](https://github.com/rails-api/active_model_serializers/pull/1482) Document JSON API implementation defs and progress in class. (@bf4)
|
||||
|
||||
@ -43,6 +43,28 @@ Use either the `JSON` or `JSON API` adapters if you want the response document t
|
||||
It's the default adapter, it generates a json response without a root key.
|
||||
Doesn't follow any specific convention.
|
||||
|
||||
##### Example output
|
||||
|
||||
```json
|
||||
{
|
||||
"title": "Title 1",
|
||||
"body": "Body 1",
|
||||
"publish_at": "2020-03-16T03:55:25.291Z",
|
||||
"author": {
|
||||
"first_name": "Bob",
|
||||
"last_name": "Jones"
|
||||
},
|
||||
"comments": [
|
||||
{
|
||||
"body": "cool"
|
||||
},
|
||||
{
|
||||
"body": "awesome"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### JSON
|
||||
|
||||
The response document always with a root key.
|
||||
@ -51,11 +73,72 @@ The root key **can't be overridden**, and will be derived from the resource bein
|
||||
|
||||
Doesn't follow any specific convention.
|
||||
|
||||
##### Example output
|
||||
|
||||
```json
|
||||
{
|
||||
"post": {
|
||||
"title": "Title 1",
|
||||
"body": "Body 1",
|
||||
"publish_at": "2020-03-16T03:55:25.291Z",
|
||||
"author": {
|
||||
"first_name": "Bob",
|
||||
"last_name": "Jones"
|
||||
},
|
||||
"comments": [{
|
||||
"body": "cool"
|
||||
}, {
|
||||
"body": "awesome"
|
||||
}]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### JSON API
|
||||
|
||||
This adapter follows **version 1.0** of the [format specified](../jsonapi/schema.md) in
|
||||
[jsonapi.org/format](http://jsonapi.org/format).
|
||||
|
||||
##### Example output
|
||||
|
||||
```json
|
||||
{
|
||||
"data": {
|
||||
"id": "1337",
|
||||
"type": "posts",
|
||||
"attributes": {
|
||||
"title": "Title 1",
|
||||
"body": "Body 1",
|
||||
"publish-at": "2020-03-16T03:55:25.291Z"
|
||||
},
|
||||
"relationships": {
|
||||
"author": {
|
||||
"data": {
|
||||
"id": "1",
|
||||
"type": "authors"
|
||||
}
|
||||
},
|
||||
"comments": {
|
||||
"data": [{
|
||||
"id": "7",
|
||||
"type": "comments"
|
||||
}, {
|
||||
"id": "12",
|
||||
"type": "comments"
|
||||
}]
|
||||
}
|
||||
},
|
||||
"links": {
|
||||
"post-authors": "https://example.com/post_authors"
|
||||
},
|
||||
"meta": {
|
||||
"rating": 5,
|
||||
"favorite-count": 10
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Included
|
||||
|
||||
It will include the associated resources in the `"included"` member
|
||||
|
||||
Loading…
Reference in New Issue
Block a user