Skip to content

JSONAPI resource relation urls #834

Closed
@lsylvester

Description

Currently, the jsonapi adapter adds resource relationships as link objects with ids and types. The jsonapi spec also allows the the resource relationship to be defined as a URL (see http://jsonapi.org/format/#document-structure-resource-relationships). For example:

{
  "type": "articles",
  "id": "1",
  "links": {
    "comments": "http://example.com/articles/1/comments"
  }
}

There is currently no way to do this using ActiveModel::Serializers as far as I can tell.

I propose that there should be a :url option for the assoications methods has_many and belongs_to that can be used to generate an resource url instead of linked objects, so that the above resource could be generated by the following serializer:

class ArticleSerializer
  has_many :comments, url: [:article, :comments]
end

I am not sure if this option is useful for the other serializers, so feedback on this would be appreciated.

If you are happy with this suggestion I can work on the implementation for this.

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions