Hi Community!
I have the following API design question.
What is the best approach for passing ranges and arrays to a GET request?
I have these use cases:
What I can think of is:
/People?age={10,20,30} <-- accolades = array
/People?age=(10,45) <-- brackets = range
or
/People?age=(10,20,30) <-- comma = array
/People?age=(10-45) <-- dash = range
Are these correct ways and is there any best practice?
Kind regards,
Jan Willem
Solved! Go to Solution.
I hesitate to claim this is the "best" approach, but here's where I would start with this one. First, I see this as two different cases, and because of that I would approach this two different ways.
In the first, where we are searching for people of specific ages (array case), I would just use multiple age parameters, e.g.
GET /people?age=10&age=20&age=30
In the second, where we are searching for people within a range of ages, I would use two different query parameters, e.g.
GET /people?minage=10&maxage=45
I like this because I think it's harder to make a mistake. I don't need to remember a specific convention, etc.
User | Count |
---|---|
1 | |
1 | |
1 | |
1 | |
1 |