How can I get a REST resource using different search methods?
Let's say you have a resource / company that allowed customers to search for public companies and you wanted customers to be able to search for businesses by ticker, location, location and industry
You would store the same url in the form:
- GET / companies / msft
- GET / companies / usa
- GET / companies / usa & software
It doesn't seem right. Any ideas?
source to share
What about?
GET /Companies?ticker=MSFT
GET /Companies?country=USA
GET /Companies?country=USA&industry=software
It is important to identify the resource. A resource is a "list of companies". Its media type can be an Atom list or just an HTML document using UL LI tags. Query parameters affect the contents of the list, but conceptually it is still a "list of companies".
You can create a separate resource like
GET /Companies/USA
but you really need to. Are you going to travel to / Companies / USA? Are you going to delete / Companies / USA? If your application doesn't require the ability to perform additional operations on these specific sets of companies, then why would they model them as separate resources?
As a side note to this discussion, I would like to differentiate more clearly when I access a resource that is a single entity and a list. i.e.
GET /Companies/USA
GET /Company/MSFT
I realize this is not how some of the popular web frameworks work, but I found it a useful distinction.
source to share