Create single and multiple resources using restful HTTP

前端 未结 5 931
时光取名叫无心
时光取名叫无心 2021-02-07 00:21

In my API server I have this route defined:

POST /categories

To create one category you do:

POST /categories {\"name\": \"Books         


        
5条回答
  •  借酒劲吻你
    2021-02-07 01:05

    In true REST, you should probably POST this in multiple separate calls. The reason is that each one will result in a new representation. How would you expect to get that back otherwise.

    Each post should return the resultant resource location:

    POST -> New Resource Location
    POST -> New Resource Location
    ...
    

    However, if you need a bulk, then create a bulk. Be dogmatic where possible, but if not, pragmatism gets the job done. If you get too hung up on dogmatism, then you never get anything done.

    Here is a similar question

    Here is one that suggests HTTP Pipelining to make this more efficient

提交回复
热议问题