Take the following example:
We want to infer company and employee information from the RESTful API.
Company data should be quite simple:
GET api/v1/companies GET api/v1/companies/{id}
Employees GET companies, but we still want to get them separately, so the best solution:
Solution 1: Using Sub-Resources
Get all employees for the company:
GET api/v1/companies/{companyId}/employees
Get a specific employee:
GET api/v1/companies/{companyId}/employees/{employeeId}
Solution 2. Use of independent resources
Get all employees for the company:
GET api/v1/employees?companyId={companyId}
Get a specific employee:
GET api/v1/employees/{employeeId}
Both options seem to have their pros and cons.
With sub-resources, CompanyId may not always be available to me when you want to get an individual employee.
With an independent resource, so that all employees of the company should use a sub-resource approach if we want to be RESTful.
Otherwise, we could use a mix, but this does not match the sequence:
Get all employees for the company:
GET api/v1/companies/{companyId}/employees
Get a specific employee:
GET api/v1/employees/{employeeId}
What is the best approach to this situation if we want to stay true to RESTful standards?