Default Behavior
You may need to change the default behavior or your API - perhaps you want a default of 10 per page instead of 20. JSONAPI Suite provides facilities that enable defaults that can be overridden - 10 per page, unless elsewise specified by the user.
You can see these defaults in the Resource documentation:
These can all be overriden by the user. In other words, hitting
/posts
will only show active Post
s, hitting
/posts?filter[active]=false
will show inactive Post
s. The same applies
for sorting and pagination.
A common pattern is for default filters to apply for all users, but
allow overrides for administrators. You can use the :if
option to
restrict the override:
Now the default behavior is to view only active Post
s, but
administrators can override this default.
You also have access to the context (in Rails, the controller) as the
last argument to default_filter
: