REST URI convention - Singular or plural name of resource while creating it

前端 未结 22 2219
长情又很酷
长情又很酷 2020-12-02 03:35

I\'m new to REST and I\'ve observed that in some RESTful services they use different resource URI for update/get/delete and Create. Such as

  • Create - using
22条回答
  •  天涯浪人
    2020-12-02 03:57

    The premise of using /resources is that it is representing "all" resources. If you do a GET /resources, you will likely return the entire collection. By POSTing to /resources, you are adding to the collection.

    However, the individual resources are available at /resource. If you do a GET /resource, you will likely error, as this request doesn't make any sense, whereas /resource/123 makes perfect sense.

    Using /resource instead of /resources is similar to how you would do this if you were working with, say, a file system and a collection of files and /resource is the "directory" with the individual 123, 456 files in it.

    Neither way is right or wrong, go with what you like best.

提交回复
热议问题