RESTful URLs for distinct versions of a resource

前端 未结 4 2090
借酒劲吻你
借酒劲吻你 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:00

    I have a use case where the creation time of each version is crucial. So common questions that the API must answer are:

    1. What is the most recent version of /recipes/ultimate-thing?
    2. What version of /recipes/ultimate-thing was the most recent on 2019-01-01?
    3. What versions of /recipes/ultimate-thing were created between 2019-01-01 and and 2019-01-31?

    Number 3. seems to me an obvious case for for query parameters:

    -- /recipes/ultimate-thing?versions_since=2019-01-01&versions_until=2019-01-31
    

    It will probably not hurt to use the same approach for 2.:

    -- /recipes/ultimate-thing?version=2019-01-01
    

    Then let's be consistent and use the same approach for 1.:

    -- /recipes/ultimate-thing?version=latest
    

    From this point of view your option 1) - using query parameters - seems most natural.

提交回复
热议问题