Skip to content

Instantly share code, notes, and snippets.

@Aslan11
Created March 23, 2016 23:10
Show Gist options
  • Save Aslan11/2c7e687db75357080d37 to your computer and use it in GitHub Desktop.
Save Aslan11/2c7e687db75357080d37 to your computer and use it in GitHub Desktop.
Endpoint Design Question - Filtering
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
Copy link

ghost commented Mar 23, 2016

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.

  • it's more explicit about what is being returned
  • it's less confusing if there are two flags being set (what if someone manages to send active=true&inactive=true ?)
  • a string tied to a generic type will just have to get mapped to explicit meaning anyway

@qiao-meng-zefr
Copy link

BTW for solution 2, the =true part can probably be removed. So you can just use /v2/ios/?active and /v2/ios/?inactive.

@Aslan11
Copy link
Author

Aslan11 commented Mar 23, 2016

good point @qiao-meng-zefr!

@mark-kawakami-zefr
Copy link

In this case, I definitely like #1 because it maps to how the data is actually represented when it comes back from the API

@mvillalobosj
Copy link

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