Let's face it - query parameters to search API endpoints are getting pretty crazy. Certain people like to use the q
parameter, some people search by field name, some through some other bunch of standards. People look to existing APIs to help them define a consistent approach but there is no de facto standard.
We here at Member get Member Company want to change that.
What the hell are we going on about, you say?
https://api.example.com/users?username=steve
This works well enough to find a user with the username of "steve", but an exact text match may not be what you want to find.
So without further ado, here's how we propose APIs should be queried!
https://api.example.com/users?username=steve
https://api.example.com/users?username=*steve*
https://api.example.com/users?age=18...25
https://api.example.com/users?friends=12,15,22
We use familiar operators - >
, <
, >=
, <=
(shown URI-encoded)
https://api.example.com/users?age=%3E18
https://api.example.com/users?age=%3C25
https://api.example.com/users?age=%3E%3D18
https://api.example.com/users?age=%3C%3D25
Default is ascending, negating with a -
sets to descending.
https://api.example.com/users?order=createdAt
https://api.example.com/users?order=-createdAt
A limit=0
sets no limit.
https://api.example.com/users?limit=5
https://api.example.com/users?limit=0
https://api.example.com/users?page=1&perPage=20
It should be possible to search for the opposite of a query by adding the !
operator to it to negate it like so:
https://api.example.com/users?status=!deleted