From bfff46b66e41387fa40233c0ff5f4073571c42d4 Mon Sep 17 00:00:00 2001 From: Ben Mills Date: Thu, 17 Mar 2016 14:04:02 -0600 Subject: [PATCH] Add output examples to Adapters docs --- CHANGELOG.md | 1 + docs/general/adapters.md | 83 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a7138ca8..a37fbc75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/docs/general/adapters.md b/docs/general/adapters.md index fa2a1531..68fe3f66 100644 --- a/docs/general/adapters.md +++ b/docs/general/adapters.md @@ -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