Created
March 23, 2016 23:10
-
-
Save Aslan11/2c7e687db75357080d37 to your computer and use it in GitHub Desktop.
Endpoint Design Question - Filtering
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PROBLEM: | |
I need to filter on a list of IO's based on active state. Given that this will be passed in from a querystring param, | |
how should I design the endpoint? | |
1. Solution 1 - Single Boolean | |
GET /v2/ios/?active=true -> Returns all the ACTIVE IO's | |
GET /v2/ios/?active=false -> Returns all the INACTIVE IO's | |
GET /v2/ios/ -> Returns both ACTIVE and INACTIVE IO's | |
2. Solution 2 - Double Boolean | |
GET /v2/ios/?active=true -> Returns all the ACTIVE IO's | |
GET /v2/ios/?inactive=true -> Returns all the INACTIVE IO's | |
GET /v2/ios/ -> Returns Both ACTIVE and INACTIVE IO's | |
3. Solution 3 - String | |
GET /v2/ios/?type=active -> Returns all the ACTIVE IO's | |
GET /v2/ios/?type=inactive -> Returns all the INACTIVE IO's | |
GET /v2/ios/?type=both -> Returns Both ACTIVE and INACTIVE IO's | |
GET /v2/ios/ -> Returns Both ACTIVE and INACTIVE IO's |
BTW for solution 2, the =true
part can probably be removed. So you can just use /v2/ios/?active
and /v2/ios/?inactive
.
good point @qiao-meng-zefr!
In this case, I definitely like #1 because it maps to how the data is actually represented when it comes back from the API
agreed, solution 1 is the best way to go
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use Solution 1, assuming that it's reasonable to return both types of IO's in your default state. (Else, just choose & document a default for the API.) Main reasoning: it's the simplest / clearest.