Rest API设计 - 发布并放入有序的子资源

时间:2015-01-11 17:27:36

标签: rest

我正在为食谱设计和构建API。我对配方资源上的crud操作很满意。 例如

GET api/recipe - returns all recipes
POST api/recipe (with json recipe in body) - creates a new recipe
GET api/recipe/23 - returns recipe 23
PUT api/recipe/23 (with json recipe in body) - update recipe
DELETE api/recipe/23 - deletes the recipe

我正在努力处理指令的子资源,即api / recipe / 23 /指令,特别是post和put。

GET api/recipe/23/instruction - returns all recipe 23 instructions
POST api/recipe/23/instruction (with json list of instructions) - adds a new list of instructions
PUT api/recipe/23/instruction (with json list of instructions) - replaces list of instructions

GET api/recipe/23/instruction/1 - returns the first instruction
POST api/recipe/23/instruction/2 - inserts an instruction at that location
PUT api/recipe/23/instruction/1 (with json instruction in body) - updates that instruction
DELETE api/recipe/23/instruction/1 - deletes the instruction

以下是我的问题

  1. 您是否可以发布列表?如果是,因为instructionId将是它出现的顺序,是否应该在POST中填充instructionId?

  2. 您是否可以提供新的指示清单以替换它们?

  3. 您是否可以POST到特定的指令ID以在订单中插入项目?响应只是URI还是完整列表?

  4. 如果有6条指令并且在指令2上完成了DELETE,那么可以重新排序指令吗?如果是这样,应该做出什么反应呢?新的指示清单?

  5. 对我来说,指令列表的PUT与对特定instructionId的POST一起感觉不太正确。

0 个答案:

没有答案