View Source Resourceful.JSONAPI.Params (Resourceful v0.1.5)
Functions for converting URL parameters into Resourceful
queries.
Additionally validates parameters when JSON:API-specific parameters are
provided such as fields
.
While JSON:API specifically designates the format for sparse fieldsets and sorting, filtering and pagination is left up to the implementation. Filtering is build around the generic queries in Resourceful and is therefore opinionated in format. Pagination supports a page number and limit/offset strategies.
There is currently no support for include
.
comma-separated-lists-and-arrays
Comma-Separated Lists and Arrays
The JSONAPI spec shows examples of
sparse fieldsets and
sorting using comma-separated
strings to represent arrays of fields. In addition to the standard form, this
library will also accept an actual array of strings. The errors that are
returned will differ depending on the form--specifically, the :input
and
:source
values. This is intentional behavior.
For example, sort=-field1,field2
and sort[]=-field1&sort[]=field2
will
return identitcal results if the fields are correct for the type, however
if field1
is invalid the errors will look slightly different:
String list:
{:invalid_jsonapi_field, %{input: "field1,field2", key: "field1", source: ["sort"]}}
Array:
{:invalid_jsonapi_field, %{input: "field1", key: "field1", source: ["sort", 0]}}