Resources are where you define how to query and persist a given
We'll wire-up the JSONAPI contract for you, so you can customize hooks rather
than spend your time parsing query parameters.
To the right, you'll see potential overrides of default behavior. Our defaults are based on
and Rails conventions - so customizations like this are often not required.
If you find yourself writing the same customizations over and over again, DRY them up by writing an Adapter.
Serializers define the structure of the response.
You're probably already familiar with the concept of "sideloading", documented in the "Inclusion of Related Resources" section of the JSONPI spec.
If using an
, such as the default
you can do this with simple
If not using an adapter, or to implement a one-off customization,
you can drop down to the lower-level
allow_sideload DSL. Adapter
macros are simply wrapping this DSL.
allow_sideload specifies two simple
- scope: specifies how to build a scope that satisifes the association.
- assign: specifies how to associate the resulting records with their parent association.
You can see the default
ActiveRecord implementation on the right.
We want to be able to *write* a nested relationship graph.
You can do this by mirroring the same
you see in read requests. To the right, you'll see we're updating a
Post, changing the name of its associated
Blog, creating a
Tag, deleting one
Comment, and disassociating (
null foreign key) a different
Comment, all in a single request.
When we send RESTful resources to the server, we typically send a corresponding HTTP verb.
method section of the payload.
method can be either
When creating, there is no
id to pass. Instead, pass
temp-id, a random uuid used to
link the relevant sections of the payload, and which tells clients how to associate
their in-memory objects with the
ids returned from the server. Clients like
JSORM will take care of this for you automatically.
When we actually perform these operations, everything will run within a transaction. The
transaction will be rolled back if an error is raised or the
Models, do not pass validation.