Sha256: 86c8520ac37aca254b5637cf43033dfdd04774321ff47611f26cbbf47b834946

Contents?: true

Size: 1.64 KB

Versions: 9

Compression:

Stored size: 1.64 KB

Contents

# Adapters

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 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

### FlattenJSON - Default

It's the default adapter, it generates a json response without a root key.
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 to the objects being serialized.
Doesn't follow any specifc convention.

### JSONAPI

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.

```ruby
  render @posts, include: ['authors', 'comments']
  # or
  render @posts, include: 'authors,comments'
```

## Choosing an adapter

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
```

or

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

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
```

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
cheap_ams-0.10.8 docs/general/adapters.md
cheap_ams-0.10.7 docs/general/adapters.md
cheap_ams-0.10.6 docs/general/adapters.md
cheap_ams-0.10.5 docs/general/adapters.md
cheap_ams-0.10.4 docs/general/adapters.md
cheap_ams-0.10.3 docs/general/adapters.md
cheap_ams-0.10.2 docs/general/adapters.md
cheap_ams-0.10.1 docs/general/adapters.md
cheap_ams-0.10.0.rc2 docs/general/adapters.md