Reputation: 822
Let's say I have two models. Project
and Task
. A task is must belongs to a project.
Which of the following URL endpoints is best practice?
https://api.myapp.com/projects/:project_id/tasks/:task_id
https://api.myapp.com/tasks/:task_id?project_id=:project_id
For filtering result I always use query params but I wondering what SHOULD we do with required params?
Upvotes: 2
Views: 7073
Reputation: 467
According to the REST best practices, a resource member should be in the url. In your case this means:
Query parameters should be used as filters. For example to get all tasks whose name begins with "TEST"/
https://api.myapp.com/projects/:project_id/tasks/:task_id?nameStartsWith=TEST
You can read more about it in here: http://www.restapitutorial.com/resources.html Download the PDF and take a look at page 14 - Resource naming.
Upvotes: 6