You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
AMS does this through two components: **serializers** and **adapters**.
4
+
Serializers describe _which_ attributes and relationships should be serialized.
5
+
Adapters describe _how_ attributes and relationships should be serialized.
6
+
You can use one of the built-in adapters (```FlattenJSON``` is the default one) or create one by your one but you won't need to implement an adapter unless you wish to use a new format or
7
+
media type with AMS.
8
+
9
+
## Built in Adapters
10
+
11
+
### FlattenJSON - Default
12
+
13
+
It's the default adapter, it generates a json response without a root key.
14
+
Doesn't follow any specifc convention.
15
+
16
+
### JSON
17
+
18
+
It also generates a json response but always with a root key. The root key **can't be overridden**, and will be automatically defined accordingly with the objects being serialized.
19
+
Doesn't follow any specifc convention.
20
+
21
+
### JSONAPI
22
+
23
+
This adapter follows 1.0 of the format specified in
24
+
[jsonapi.org/format](http://jsonapi.org/format). It will include the associated
25
+
resources in the `"included"` member when the resource names are included in the
26
+
`include` option.
27
+
28
+
```ruby
29
+
render @posts, include: ['authors', 'comments']
30
+
# or
31
+
render @posts, include:'authors,comments'
32
+
```
33
+
34
+
## Choose an Adapter
35
+
36
+
If you want to use a different adapter, such as a JsonApi, you can change this in an initializer:
Add the root key to your API is quite simple with AMS. The **Adapter** is what determines the format of your JSON response. The default adapter is the ```FlattenJSON``` which doesn't have the root key, so your response is something similar to:
4
+
5
+
```json
6
+
{
7
+
id: 1,
8
+
title: "Awesome Post Tile",
9
+
content: "Post content"
10
+
}
11
+
```
12
+
13
+
In order to add the correspondent root key you need to use the ```JSON``` Adapter, you can change this in an initializer:
0 commit comments