Say I have a company directory application, so Companies
have Employees
. It's pretty clear to me why you would have the following GET
endpoints:
api/companies # Get all company records
api/companies/{id} # Get company with specified id
api/companies/{id}/employees # Get all employees for the company with specified id
But say I want to get a specific employee record. It seems the common pattern is to provide a resource:
api/companies/{id}/employees/{id}
But assuming an employee
record is only owned by one company
, why would you provide the company
's id in that URI? Isn't that simply a redundant parameter? Even if you need to acquire the company
for some kind of logic behind the scenes, you can do that easily enough by just checking the parent of the employee
. So my gut says to make the endpoint like this:
api/companies/employees/{id}
Yet the former pattern is so pervasive, I feel like I'm missing something. Would someone care to explain?