I am trying to figure out the best/right way to design the URLs of my rest api but I am confuse in between a company
resource.
This is a company
resource located at http://localhost:8085/api/v1/company/1
. This will return me some basic data from a table company
.
Fine till now. But now the company can be of two types: 1. Mechanical 2. Other. Each has their respective table in DB with 1:1
relationship with company
table. To fetch the further details about the company, I need to expose the other two tables from some API endpoint.
So, I am confused in between three URLs here:
http://localhost:8085/api/v1/company/1?type=mechanical
http://localhost:8085/api/v1/company/1/mechanical
http://localhost:8085/api/v1/company/mechanical/1
I reject option 1 for one reason I found on SO, i.e paths having parameters cannot be cached. Rest Standard: Path parameters or Request parameters
I am mainly confused in between 2 and 3? What would be the correct way?
One question you may ask, why not I am providing the complete company information from http://localhost:8085/api/v1/company/1
? That's because I want to take advantage of Lazy Loading. Details for the company could take more time to fetch, so I separated the contents.