-
Notifications
You must be signed in to change notification settings - Fork 535
JSONAPI::Resources Querystring Examples
Brent Jubinville edited this page Feb 4, 2016
·
11 revisions
The purpose of this article is to correlate querystring parameter usage in jsonapi-resources with the jsonapi specification
Given the example resource:
class UserResource < JSONAPI::Resource
attribute :first_name
attribute :last_name
attribute :email
attribute :created_at
attribute :updated_at
paginator :offset
end
and the following route (in routes.rb
):
jsonapi_resources :users
we can do the following:
Ascending By A Property: /users?sort={property-name}
- the property name must be dasherized
- e.g.
/users?sort=last-name
will sort the collection ascending by last name (A-Z)
Descending By A Property: /users?sort=-{property-name}
- the sort parameter is prepended by a
-
- the property name must be dasherized
- e.g.
/users?sort=-last-name
will sort the collection descending by last name (Z-A)
Provided pagination has been enabled for your application or resource (see README.md):
Limiting Returned Resources: /users?page[limit]={resource_count}
-
{resource_count}
= number of resources you want returned - e.g.
/users?page[limit]=5
will return the first 5user
resources
Offsetting/Paging Returned Resources: /users?page[offset]={resource_offset}
-
{resource_offset}
= the number of records to offset by prior to returning resources - e.g.
/users?page[offset]=10
will skip the first 10user
resources in the collection
Combining Limiting/Offsetting: /users?page[limit]={resource_count}&page[offset]={resource_offset}
- e.g.
/users?page[limit]=5&page[offset]=10
will skipuser
resources 0-10 and return resources 11-15