README.md in jsonapi-serializers-0.13.0 vs README.md in jsonapi-serializers-0.14.0

- old
+ new

@@ -17,12 +17,14 @@ * [Multiple attributes](#multiple-attributes) * [Custom attributes](#custom-attributes) * [More customizations](#more-customizations) * [Base URL](#base-url) * [Root metadata](#root-metadata) + * [Root links](#root-links) * [Root errors](#root-errors) * [Explicit serializer discovery](#explicit-serializer-discovery) + * [Namespace serializers](#namespace-serializers) * [Relationships](#relationships) * [Compound documents and includes](#compound-documents-and-includes) * [Relationship path handling](#relationship-path-handling) * [Control links and data in relationships](#control-links-and-data-in-relationships) * [Rails example](#rails-example) @@ -315,10 +317,18 @@ ```ruby JSONAPI::Serializer.serialize(post, meta: {copyright: 'Copyright 2015 Example Corp.'}) ``` +### Root links + +You can pass a `links` argument to specify top-level links: + +```ruby +JSONAPI::Serializer.serialize(post, links: {self: 'https://example.com/posts'}) +``` + ### Root errors You can use `serialize_errors` method in order to specify top-level errors: ```ruby @@ -358,9 +368,39 @@ end end ``` Now, when a `User` object is serialized, it will use the `SomeOtherNamespace::CustomUserSerializer`. + +### Namespace serializers + +Assume you have an API with multiple versions: + +```ruby +module Api + module V1 + class PostSerializer + include JSONAPI::Serializer + attribute :title + end + end + module V2 + class PostSerializer + include JSONAPI::Serializer + attribute :name + end + end +end +``` + +With the namespace option you can choose which serializer is used. + +```ruby +JSONAPI::Serializer.serialize(post, namespace: Api::V1) +JSONAPI::Serializer.serialize(post, namespace: Api::V2) +``` + +This option overrides the `jsonapi_serializer_class_name` method. ## Relationships You can easily specify relationships with the `has_one` and `has_many` directives.