Skip to content

JSONAPI::Resources Querystring Examples

Brent Jubinville edited this page Feb 4, 2016 · 11 revisions

Overview

The purpose of this article is to correlate querystring parameter usage in jsonapi-resources with the jsonapi specification

Examples

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:

Sorting

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)
Clone this wiki locally