How to return random items RESTfully?

后端 未结 5 1542
有刺的猬
有刺的猬 2021-02-06 03:19

My design exposes two kinds of resources:

  1. Images
  2. Tags

I would like clients to be able to request random images by their tag(s). For example

5条回答
  •  灰色年华
    2021-02-06 03:28

    Multi-dimensional resource identification is challenging.

    Your resource is an image, so that's your URI. Further, a specific image has a specific URI which never changes.

    Your "by tag" is a non-identifying attribute of the resource. For this, a query string can belp.

    Here's my first thought.

    • http://www.example.com/MyStuff/image/id/ -- specific image by id
    • http://www.example.com/MyStuff/image/?tag=tagname -- random image with a given tag, implicitly, count=1.
    • http://www.example.com/MyStuff/image/?tag=tagname&count=all -- all images with a given tag in a random order (count=1 is the default, which would give you an arbitrary image)

提交回复
热议问题