Sha256: 3503faba45d40707cd449c965874a4e269e41280848b4d9e1d4705bbd7459fe8

Contents?: true

Size: 1.66 KB

Versions: 20

Compression:

Stored size: 1.66 KB

Contents

# *Flexirest:* JSON API

If you are working with a [JSON API](http://jsonapi.org), you need to activate JSON API by specifying the `json_api` proxy:

```ruby
class Article < Flexirest::Base
  proxy :json_api
end
```

This proxy translates requests according to the JSON API specifications, parses responses, and retrieves linked resources. It also adds the `Accept: application/vnd.api+json` header for all requests.

It supports lazy loading by default. Unless a compound document is returned from the connected JSON API service, it will make another request to the service for the specified linked resource.


## Including associations

To reduce the number of requests to the service, you can ask the service to include the linked resources in the response. Such responses are called "compound documents". To do this, use the `includes` method:

```ruby
# Makes a call to: /articles?include=images
Article.includes(:images).all

# Fetch nested resources: /articles?include=images.tags,images.photographer
Article.includes(:images => [:tags, :photographer]).all

# Note: the `includes` method takes precedence over the passed `:include` parameter.
# This will result in query: /articles?include=images
Article.includes(:images).all(include: "author")
```

## Resource type

The `type` value is guessed from the class name, but it can be set specifically with `alias_type`:

```ruby
class Photographer < Flexirest::Base
  proxy :json_api
  # Sets the type in the resource object to "people"
  alias_type :people

  patch :update, '/photographers/:id'
end
```


## Notes

Updating relationships is not yet supported.


-----

[< Plain requests](plain-requests.md) | [Proxying APIs >](proxying-apis.md)

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
flexirest-1.12.4 docs/json-api.md
flexirest-1.12.3 docs/json-api.md
flexirest-1.12.2 docs/json-api.md
flexirest-1.12.1 docs/json-api.md
flexirest-1.12.0 docs/json-api.md
flexirest-1.11.3 docs/json-api.md
flexirest-1.11.2 docs/json-api.md
flexirest-1.11.1 docs/json-api.md
flexirest-1.11.0 docs/json-api.md
flexirest-1.10.12 docs/json-api.md
flexirest-1.10.11 docs/json-api.md
flexirest-1.10.10 docs/json-api.md
flexirest-1.10.9 docs/json-api.md
flexirest-1.10.8 docs/json-api.md
flexirest-1.10.7 docs/json-api.md
flexirest-1.10.6 docs/json-api.md
flexirest-1.10.5 docs/json-api.md
flexirest-1.10.4 docs/json-api.md
flexirest-1.10.3 docs/json-api.md
flexirest-1.10.2 docs/json-api.md