Reputation: 4247
We have several API endpoints like:
/api/cities/ => Fetches all cities in our database. Its an oversimplified example, actually we have around 1k cities.
{
"name": "Chicago",
"name": "Los Angeles",
"name": "New York",
"name": "Phoenix"
}
Currently these API returns city list in alphabetic order.
We have new requirement where we need to fetch popular cities at the top, this followed by list in alphabetic order.
JSON Output would look like:
{
"popular"
{
"name": "New York",
"name": "Los Angeles"
},
"all"
{
"name": "Chicago",
"name": "Los Angeles",
"name": "New York",
"name": "Phoenix"
}
}
How should current APIs be modified to fulfil this:
Or any other thing, this doesn't look like filter attribute as this is actually adding result at the top and not filtering it out.
We do need to repeat popular cities in all city list as this would be binded directly to UI dropdown and requirement is to keep alphabetic ordering intact.
Suggestions?
Upvotes: 0
Views: 237
Reputation: 1820
you can use both endpoint, a endpoint like as shortcut of api fetch all with order by popular.
Upvotes: 0
Reputation: 5187
popular
cities are a way of sorting for the same entities.
It shouldn't be a new resource, but a way of querying the same resource sorted differently to get the needed entries.
I would use a query for that: ?sort=popular
.
Upvotes: 1