I'm building a REST API, and I have some relationships that are making my links very long. They make sense to me, but it's a mess. I'm not sure what the best way is to handle this. Is it a problem to have links that are so long? Am I violating a principle with these? How should I handle relationships like this?
The example below is a bit contrived, but it illustrates what I'm trying to do.
A company has many departments. Each department has many employees. Each employee can have many computers. Each computer can have many documents on it.
The path to GET a specific document would be:
/companies/:companyId/departments/:departmentId/employees/:employeeId/computers/:computerId/documents/:documentId Each ID is globally unique within that layer--no two document IDs will be the same across the entire system, but a document ID could be the same as an employee ID.
This makes sense to me, because each layer is only associated with the one thing above it. A department will belong only to a single company, an employee to only a single department, a computer to only a single employee, and a document to only a single computer.
I could break these out into separate endpoints, such as /computers, but then how would I know where to break them? Why would I choose /computers as the endpoint and not /employees/:employeeId/computers?
GET /documents?computerId=123, or extend computers toGET /computers/:computerId/documents?