0

Suppose we have a resource which uses either MySQL or ElasticSearch, depending on whether the query params require full-text search or not.

For example the possible query filters are: fk_id which is a foregien key ID of the table, name and description which requires full-text search.

Should the resource URLs be:

  • Option 1 - one endpoint: /resources?fk_id=abc&name=my_name
  • Option 2 - two endpoints
    • /resources?fk_id=abc -- name is not a valid param.
    • /resources/search?q=name:my_name&fk_id=abc

Which of the following is a better option for a general purpose API?

1 Answer 1

2

REST doesn't care. The fact that you are using databases rather than the file system, and two databases rather than one, is an implementation detail that is hidden behind the web interface.

As long as your server can figure out where the information is for each possible combination of query parameters, using the same path segment is fine.

If instead, using two different path segments makes your life easier? That's also fine.


URI design is a lot like choosing variable names, or file names - the machines don't care, so you can choose any spelling that makes life easier for the human beings that you care about.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.