Search code examples
restapi-design

How to design a REST resource to find objects from different resources?


I have resources:

/countries/
/countries/{countryName}/
/countries/{countryName}/cities/
/countries/{countryName}/cities/{cityName}

I want to add the ability to the REST API to get the cities of any country with a specific name (or meeting other criteria, such as population, area, etc). How could I do that (what resource and method should I make)?


Solution

  • I would say make a resource

    /cities
    

    And make it POST and pass your query params as JSON doc