开发者

What is the preferred Restful URI design to distinguish between a collection and singleton resource?

I have a URI structure which is hierarchical for a particular data set:

/Blackboard/Requirement/{reqID}/Risk/{riskId}/MitigationPlan/{planId}

If the url is split at various IDs you can get that particular resource e.g.:

GET: /Blackboard/Requirement/2/Risk/2

This gets Risk #2 associated with Requirement #2

The question is this: a desired feature is now to be able to update (PUT) and delete (DELETE) a set of requirements in the same HTTP request. (The entire 'set' of requirements is GET-able when you fire an HTTP GET to the /Blackboard URL - that's the default functionality since something is written on the blackboard, figuratively)

So should I create a new collection resource URL only supporting PUT/DELETE like this:

/Blackboard/Requirements : HTTP PUT/DELETE

(note the plural)

or actually make the existing URL structure plural

/Blackboard/Requirements/{reqID}/Risk/{riskId}/MitigationPlan/{planId}

The latter seems to break semantic uniformity since the other items in the hierarchy are singular. Should I make them plural too??

Does having an item id help disambiguate singularity (from a human perspectiv开发者_StackOverflow社区e :) like Blackboard/Requirements/1 or is it preferable to expose a different resource (i.e., a collection) purely for operational reasons (since GET is not allowed without id - irrespective of it being singular or plural)?

Just wanted to know the opinions of the community on which approach is commonly chosen (or is the right way of doing it) for clarity cleaner design.


The latter seems to break semantic uniformity since the other items in the hierarchy are singular. Should I make them plural too?

You should want your url's to be cool. So if you do change them to make it match, make sure your old singular urls return redirects with the new locations. Determining the expensive of that might help make the decision of change/no-change. If your API isn't used yet, then there's no barrier one way or the other. IMO, I'd go for consistency.

Does having an item id help disambiguate singularity (from a human perspective :) like Blackboard/Requirements/1 or is it preferable to expose a different resource (i.e., a collection) purely for operational reasons (since GET is not allowed without id - irrespective of it being singular or plural)?

For me, it makes more sense to have the url collections plural even with id. That could be a bias from file systems though. In that sense, it only makes sense that a single resource would be deeper in the url than the collection resource. It also give an easy way back to the collection resource, a url breadcrumb.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜