Operation Processors
Operation Processors are called to perform the operation(s) that make up a request. The controller (through the OperationDispatcher
), creates an OperatorProcessor
to handle each operation. The processor is created based on the resource name, including the namespace. If a processor does not exist for a resource (namespace matters), the default operation processor is used instead. The default processor can be changed by a configuration setting.
Custom OperatorProcessors
Defining a custom Processor
allows for custom callback handling of each operation type for each resource type. For example:
class Api::V4::BookProcessor < JSONAPI::Processor |
This simple example uses a callback to update the result’s meta property with the total count of records (a redundant feature only for example purposes) if there wasn’t an error in the operation. It is also possible to override the find
method as well if a different behavior is needed, for example:
class Api::V4::BookProcessor < JSONAPI::Processor |
Note: The authors of this gem expect the most common uses cases to be handled using the callbacks. It is likely that the internal functionality of the operation processing methods will change, at least for several revisions. Effort will be made to call this out in release notes. You have been warned.