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

前端 未结 22 2199
长情又很酷
长情又很酷 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:53

    Singular

    Convenience Things can have irregular plural names. Sometimes they don't have one. But Singular names are always there.

    e.g. CustomerAddress over CustomerAddresses

    Consider this related resource.

    This /order/12/orderdetail/12 is more readable and logical than /orders/12/orderdetails/4.

    Database Tables

    A resource represents an entity like a database table. It should have a logical singular name. Here's the answer over table names.

    Class Mapping

    Classes are always singular. ORM tools generate tables with the same names as class names. As more and more tools are being used, singular names are becoming a standard.

    Read more about A REST API Developer's Dilemma

    For things without singular names

    In the case of trousers and sunglasses, they don't seem to have a singular counterpart. They are commonly known and they appear to be singular by use. Like a pair of shoes. Think about naming the class file Shoe or Shoes. Here these names must be considered as a singular entity by their use. You don't see anyone buying a single shoe to have the URL as

    /shoe/23
    

    We have to see Shoes as a singular entity.

    Reference: Top 6 REST Naming Best Practices

提交回复
热议问题