Filtering in JSON:API

I needed to filter data when accessing an API following the JSON:API specifications. For those not familiar with JSON:API, it provides a set of conventions on how to structure JSON responses. It also provides some guidance on how to request data. Similar to semantic versioning, the set of conventions cuts down on the debate on how to structure APIs.

Filtering by Passing Query Parameters

JSON:API describes how to filter parameters, through the use of a filter parameter.

Example (fetching all posts made by author Joe):

http://example.com/api/posts?filter=[author][joe]

What I don’t see in the examples is how to pass in a list of values. For example, filtering by multiple authors. For now, I’ll assume that it is acceptable to pass in a list of values:

http://example.com/api/posts?filter=[author][jack,jill]

See also

Query Parameter Families

Filtering example in Drupal

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s