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

前端 未结 22 2174
长情又很酷
长情又很酷 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 04:06

    For me is better to have a schema that you can map directly to code (easy to automate), mainly because code is what is going to be at both ends.

    GET  /orders          <---> orders 
    POST /orders          <---> orders.push(data)
    GET  /orders/1        <---> orders[1]
    PUT  /orders/1        <---> orders[1] = data
    GET  /orders/1/lines  <---> orders[1].lines
    POST /orders/1/lines  <---> orders[1].lines.push(data) 
    

提交回复
热议问题