Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Starting Docs structure #994

Merged
merged 4 commits into from
Jul 17, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
minor updates and TYPOs
  • Loading branch information
João M. D. Moura committed Jul 17, 2015
commit 63436c73e8e2eb0cf05a4e0ec90ad17a7451f978
4 changes: 2 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Docs - ActiveModel::Serializer 0.10.x

This is the documentation of AMS, it's focused on **0.10.x version.**
This is the documentation of AMS, it's focused on the **0.10.x version.**

-----

Expand All @@ -11,7 +11,7 @@ This is the documentation of AMS, it's focused on **0.10.x version.**

## How to

- [How to use add root key](howto/add_root_key.md)
- [How to add root key](howto/add_root_key.md)

## Getting Help

Expand Down
13 changes: 6 additions & 7 deletions docs/general/adapters.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
AMS does this through two components: **serializers** and **adapters**.
Serializers describe _which_ attributes and relationships should be serialized.
Adapters describe _how_ attributes and relationships should be serialized.
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
media type with AMS.
You can use one of the built-in adapters (```FlattenJSON``` is the default one) or create one by yourself, but you won't need to implement an adapter unless you wish to use a new format or media type with AMS.

## Built in Adapters

Expand All @@ -15,12 +14,12 @@ Doesn't follow any specifc convention.

### JSON

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.
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 to the objects being serialized.
Doesn't follow any specifc convention.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would argue that it can't be set from the controller or render command, but it can be overridden in the serializer or by subclassing the json adapter see #986 (comment) though I'm not sure to what extent we want to highlight here, or link to it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I want to highlight this work-around now. I'm also still considering bring root option back so we might to update it soon.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh... why can't it be overridden? 😢 I think it should be...


### JSONAPI

This adapter follows 1.0 of the format specified in
This adapter follows **version 1.0** of the format specified in
[jsonapi.org/format](http://jsonapi.org/format). It will include the associated
resources in the `"included"` member when the resource names are included in the
`include` option.
Expand All @@ -31,9 +30,9 @@ resources in the `"included"` member when the resource names are included in the
render @posts, include: 'authors,comments'
```

## Choose an Adapter
## Choosing an adapter

If you want to use a different adapter, such as a JsonApi, you can change this in an initializer:
If you want to use a different adapter, such as JsonApi, you can change this in an initializer:

```ruby
ActiveModel::Serializer.config.adapter = ActiveModel::Serializer::Adapter::JsonApi
Expand All @@ -45,7 +44,7 @@ or
ActiveModel::Serializer.config.adapter = :json_api
```

If you want to have a root key on your responses you should use the Json adapter, instead of the default FlattenJson:
If you want to have a root key in your responses you should use the Json adapter, instead of the default FlattenJson:

```ruby
ActiveModel::Serializer.config.adapter = :json
Expand Down
15 changes: 5 additions & 10 deletions docs/howto/add_root_key.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# How to use add root key
# How to add root key

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:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Adding a root key"


Expand All @@ -10,19 +10,14 @@ Add the root key to your API is quite simple with AMS. The **Adapter** is what d
}
```

In order to add the correspondent root key you need to use the ```JSON``` Adapter, you can change this in an initializer:
In order to add the root key you need to use the ```JSON``` Adapter, you can change this in an initializer:

```ruby
ActiveModel::Serializer.config.adapter = :json_api
ActiveModel::Serializer.config.adapter = :json
```

or

```ruby
ActiveModel::Serializer.config.adapter = ActiveModel::Serializer::Adapter::Json
```

This will add the root key to all your serialized endpoints.
You can also specify a class as adapter, as long as it complies with the AMS adapters interface.
It will add the root key to all your serialized endpoints.

ex:

Expand Down