[关闭]
@bergus 2016-12-23T06:34:24.000000Z 字数 961 阅读 1435

REST API设计最佳实践

restful API设计


执行动作

  1. # 批量执行动作
  2. POST /api/users/actions -d {ids:[id1,id2,...],actions:["touch","rm","ls"]}
  3. # 对特定资源执行批量动作
  4. POST /api/users/{id1}/actions -d [{"actions":["touch","rm","ls"]}]
  5. # 对特定资源执行特定动作
  6. POST /api/users/{id1}/{action}

添加数据;json类型

  1. # 创建资源
  2. POST /api/users -d [{"user_name":123},{"user_name":1}]

删除数据;json类型

  1. # 批量删除数据
  2. DELETE /api/users -d {ids:[id1,id2,...],fields:[field1,field2,...],where:{field1:{">":1,"<":4}}}
  3. # 删除特定资源
  4. DELETE /api/users/{id1} -d {fields:[field1,field2,...],where:{field1:{">":1,"<":4}}},

修改数据;json类型

  1. PUT /api/users -d {ids:[id1,id2,...],fields:{field1:value1,field2:value2},where:{field1:{">":1,"<":4}}}
  2. PUT /api/users/{id1} -d {fields:{field1:value1,field2:value2},where:{field1:{">":1,"<":4}}}

获取数据;json类型

  1. GET /api/users?ids=id1,id2,id3&fields=user_name,passwd&conds=1<user_name<4&page=1&per_page=50}
  2. GET /api/users -d {ids:[id1,id2,...],fields:["user_name","passwd"],where:{field1:{">":1,"<":4}},"page":1,"per_page":50}
  3. GET /api/users/{id1} -d {fields:["user_name","passwd"]}
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注