REST Web服务API设计 [英] REST Web Services API Design

查看:121
本文介绍了REST Web服务API设计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是想获得我如何规划建筑师我的API的反馈。下面的虚拟方法。这里的结构:

  GET http://api.domain.com/1/users/<  - 返回用户的列表
POST http://api.domain.com/1/users/add.xml< - 增加用户
POST http://api.domain.com/1/users/update.xml< - 更新用户
删除(或POST?)http://api.domain.com/1/users/delete.xml< - 删除用户

问题:


  1. 是否确定只使用GET和POST?

  2. 难道我打算靠文件名来指示做什么手术好主意(例如add.xml添加)?它会更好做这样的事情:POST <一个href=\"http://api.domain.com/1/users/add/data.xml\">http://api.domain.com/1/users/add/data.xml?

  3. 什么是让这些资源版本的好办法?在我的例子,我用/ 1 /域名后,指示版本1的替代品应该是: http://api1.domain.com ...或 http://api-1.domain.com ......或者的http://apiv1.domain.com ......或者的http:// API-V1 .domain.com ......或者 http://api.domain.com/v1/ ...或

  4. 什么是身份验证的最佳方式?


解决方案

1)在您的设计可能不是。 POST是不是幂等!所以,你不应该用于更新或删除,改用PUT和DELETE休息

2),更好的选择是使用头的内容类型的在WS调用,如:应用程序/ XML

3)同样在头的Content-Type U可以使用它:应用V1.0 / XML

4)不知道这是否是最好的,但可能是最简单的方法是使用HTTP内置的身份验证机制在 RFC 2617 。举个例子: AWS认证

Just wanted to get feedback on how I am planning to architect my API. Dummy methods below. Here's the structure:

GET http://api.domain.com/1/users/ <-- returns a list of users
POST http://api.domain.com/1/users/add.xml <-- adds user
POST http://api.domain.com/1/users/update.xml <-- updates user
DELETE (or POST?) http://api.domain.com/1/users/delete.xml <-- deletes user

Questions:

  1. Is it OK to use just GET and POST?
  2. Is it a good idea that I plan to rely on the filename to indicate what operation to do (e.g. add.xml to add)? Would it be better to do something like this: POST http://api.domain.com/1/users/add/data.xml?
  3. What's a good way to keep these resources versioned? In my example, I use a /1/ after domain name to indicate version 1. Alternatives would be: http://api1.domain.com... or http://api-1.domain.com... or http://apiv1.domain.com... or http://api-v1.domain.com... or http://api.domain.com/v1/... or
  4. What's the best way to authenticate?

解决方案

1) On your design probably not. POST is not idempotent! So you should not use for the update or the delete, instead use PUT and DELETE from Rest

2) A better choice is to use the header Content-Type on the WS call, like: application/xml

3) Also on the header Content-Type u can use it: application-v1.0/xml

4) Not sure if it is the best, but probably the easiest way is to use HTTP's built-in authentication mechanisms in RFC 2617. An example: AWS Authentication

这篇关于REST Web服务API设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆