Skip to content

Instantly share code, notes, and snippets.

@liwh
Created November 7, 2011 07:12
Show Gist options
  • Select an option

  • Save liwh/1344384 to your computer and use it in GitHub Desktop.

Select an option

Save liwh/1344384 to your computer and use it in GitHub Desktop.
API设计

验证方式

包含以下两种认证方式:

响应格式

JSON 和 XML,咱时只考虑支持JSON调用

可操作资源

  • 商店(shop),只可请求本商店的内容。包含动作(RU)
  • 商品(product), 包含动作(CRUD)
  • 顾客(customer),包含动作(CRUD)
  • 订单(order), 包含动作(CRUD)
  • 订单商品(OrderLineItem),包含动作(CRUD) ...

请求格式

如请求商品id为1的商品:/api/products/1.json (默认请求格式为JSON) 如请求订单号为1的订单商品:/api/orders/1/line_items.json

查询格式

这里使用meta_search的查询方式

HTTP验证请求

  curl -u api_key:password http://example.com/api/products.json

测试工具

可使用curl用来实现CRUD操作的测试,具体使用可参考此文curl

示例

请求products列表:

 curl -u api_key:password http://example.com/api/products.json

查看id为1的product参数

  curl -u api_key:password http://example.com/api/products/1.json

修改id为1的product的标题为bbbb

curl -X PUT -u api_key:password api_key:password http://example.com/api/products/1.json -d 'product[title]=111' 

删除id为1的product

   curl -X DELETE -u api_key:password http://example.com/api/products/1.json

查询title为111的products

  curl -u api_key:password http://example.com/api/products.json  -X GET -d "search[title_eq]=111"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment