RESTful URLs for distinct versions of a resource

前端 未结 4 2088
借酒劲吻你
借酒劲吻你 2021-02-14 13:29

I\'m having a real hard time conceptually understanding something proper concerning URLs for versioned resources.

Let\'s say I have an application that tracks recipes in

4条回答
  •  清歌不尽
    2021-02-14 14:17

    Wow. Good question. I too find that one of the biggest challenges of REST is that it is a style, not a strict specification. The style seems not to be well-understood, and there is nothing that enforces it.

    Short answer: Style #1: /recipes/cake?version=2

    This style seems most appropriate to me. It was only after a quick Google search that I found that query parameters are considered part of the URI. Thus it seems appropriate to put an identifying attribute in the URI.

    Styles 2 and 3 seems to violate other REST conventions where path segments represent IDs and sub-resources. Thus the style /recipes/cake/2 looks like the "cake" resource with ID 2. /recipes/cake/version/2 makes "version" appear to be a sub-resource, when in fact it is an attribute of the parent resource.

提交回复
热议问题