JPS
JPS

Reputation: 2760

REST url for nested resources

Which is a proper way of creating REST path ? Say i have REST resource like,

base_url/api/projects/{projId}/sprints/{sprintId}/.....etc

I have more than 5 path params like this in a resource url. Is it proper to have so many path params or we have to cut it to different resources like,

base_url/api/projects/{projId}
base_url/api/sprints/{sprintId}
...etc

The condition here is , a sprint cannot exist without a project and so on. If we need to cut the resources to different paths, are there any standards on which conditions we can cut them?

Upvotes: 0

Views: 65

Answers (1)

cassiomolin
cassiomolin

Reputation: 130857

REST doesn't care about the URI design. That's a misconception.

The readability of a URI is desirable but not mandatory in the REST architectural style.


As defined in the RFC 3986, the URI syntax is organized hierarchically, with components listed in order of decreasing significance from left to right separated by /. If a sprint cannot exist without a project, you can use the following to express such hierarchy:

/api/projects/{project-id}/sprints/{sprint-id}

However, if the URI gets too long and you have many parameters to pass around, there's not issues in splitting it:

/api/projects/{project-id}
/api/sprints/{sprint-id}

Upvotes: 2

Related Questions