Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON API filtering standards for more complex queries

I am writing a REST api using ruby on rails. I am using json api as a guide for the standards to use when building the api.

I am trying to figure out the best way to use filtering in the GET requests. The json api recommendations for filtering only include where something is exactly equal to. eg.

GET /comments?filter[post]=1

How would I go about filtering for greater than, less than, not equal to, like, contains etc.?

I have done a lot of searching through google results but there doesn't seem to be a standard of the best way to do the filtering. There are some suggestions for example this one.

I'm looking for a solid spec or standard that I can refer to specifically for the filtering for my api, as the json api spec is very limited when it comes to filtering.

like image 319
David North Avatar asked Mar 17 '26 22:03

David North


1 Answers

I looks like there are a few more resources for this now 6 years later.

From what I read quickly it looks like the JSON:API spec may not specify this exactly. However this supposedly compliant framework documentation looks helpful:

https://www.jsonapi.net/usage/reading/filtering.html

Going by their method you could do this

GET /games?filter=greaterThan(id,20345)
GET /games?filter=lessThan(id,345334)

See the link as they have a lot of other standard looking filters that could be useful.

like image 82
thinktt Avatar answered Mar 20 '26 20:03

thinktt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!