Adds support for top-level links to JsonApi adapter

http://jsonapi.org/format/#document-top-level

fix failing tests

support for top-level links limited to jsonapi adapter

Move docs from README to docs/ dir

move links to json-api adapter & create Links class to hold links data
This commit is contained in:
Leandro Cesquini Pereira
2015-07-24 23:05:52 -03:00
parent 72c2c9f0d7
commit 1844c162f1
7 changed files with 195 additions and 0 deletions

View File

@@ -23,6 +23,7 @@ This is the documentation of ActiveModelSerializers, it's focused on the **0.10.
- [How to add pagination links](howto/add_pagination_links.md)
- [Using ActiveModelSerializers Outside Of Controllers](howto/outside_controller_use.md)
- [Testing ActiveModelSerializers](howto/test.md)
- [How to add top-level links](howto/add_top_level_links.md) (```JSON-API``` only)
## Integrations

View File

@@ -0,0 +1,31 @@
# How to add top-level links
JsonApi supports a [links object](http://jsonapi.org/format/#document-links) to be specified at top-level, that you can specify in the `render`:
```ruby
render json: @posts, links: { "self": "http://example.com/api/posts" }
```
That's the result:
```json
{
"data": [
{
"type": "posts",
"id": "1",
"attributes": {
"title": "JSON API is awesome!",
"body": "You should be using JSON API",
"created": "2015-05-22T14:56:29.000Z",
"updated": "2015-05-22T14:56:28.000Z"
}
}
],
"links": {
"self": "http://example.com/api/posts"
}
}
```
This feature is specific to JsonApi, so you have to use the use the [JsonApi Adapter](https://github.com/rails-api/active_model_serializers/blob/master/docs/general/adapters.md#jsonapi)