I'm developing a web-api that manages a two level hierarchy objects: Group -> SubGroup.
- The group are added only by their names and it is a unique identifier for the group
- The sub groups are added only by their names and the group name + sub group name is a unique identifier for the sub group.
- The subgroup can "live" only in the context of its parent (the group).
- Both the group and subgroup have unique ids in the system (besides the names).
The user should have an option to get a certain subgroup details and i'm uncertain if i should give him an endpoint that lets him access it directly. I researched some threads by didn't get a good answer (1,2,3)
I have two options:
Option 1:
create an endpoint that lets the user to access subgroup only by specifying its name and its parent group name:
/groups/subgroups?groupName="x"&subGroupName="y"
Option 2:
create a "direct" access endpoint that lets the user access the subgroup directly without specifying the parent group name by using its internal id (In the subgroup creation return this id) for example:
/subgroups?id="52regfd235fdsf325f" (the id of subgroup "y")
- What is the best practice for this situation? is adding a "direct" access endpoint to a nested resource is fine or it should be avoided? what will be the case for a subgroup removal endpoint for example? should it be identified by the subgroup id or by its name?
- In the general case, when we have H1->H2->H3->...Hn hierarchies. For trying to access the last resource in the chain, what will be a good rule of thumb here?