原文地址:Roy T. Fielding: REST APIs must be hypertext-driven

I am getting frustrated by the number of people calling any HTTP-based interface a REST API. Today’s example is the SocialSite REST API. That is RPC. It screams RPC. There is so much coupling on display that it should be given an X rating.
我是越来越失望了,许多人把任何基于HTTP的接口叫做REST API,眼前的例子就是SocialSite REST API。那是RPC,实实在在的RPC。它与显示如此耦合,再差也莫过于此

What needs to be done to make the REST architectural style clear on the notion that hypertext is a constraint? In other words, if the engine of application state (and hence the API) is not being driven by hypertext, then it cannot be RESTful and cannot be a REST API. Period. Is there some broken manual somewhere that needs to be fixed?
基于超文本概念,如何才能确保清晰的REST架构风格呢?这样来说吧,如果应用程序状态引擎(即API)不是由超文本驱动的,那就不是RESTful也不是REST的API。就这么简单。某些REST方面的破手册是否该修正一下呢?

API designers, please note the following rules before calling your creation a REST API:
API的设计者们,把你们的那些东西叫做REST API前请注意以下的规则:

A REST API should not be dependent on any single communication protocol, though its successful mapping to a given protocol may be dependent on the availability of metadata, choice of methods, etc. In general, any protocol element that uses a URI for identification must allow any URI scheme to be used for the sake of that identification. [Failure here implies that identification is not separated from interaction.]
REST API不应依赖于任何特定的通讯协议,在采用某个具体协议时可能受限于元数据的有效性、方法的选择等。通常,协议元素使用URI作标识时,对该标识必须允许运用任何URI方案。[ 不符合这一点意味着标识与交互没有分离 ]

A REST API should not contain any changes to the communication protocols aside from filling-out or fixing the details of underspecified bits of standard protocols, such as HTTP’s PATCH method or Link header field. Workarounds for broken implementations (such as those browsers stupid enough to believe that HTML defines HTTP’s method set) should be defined separately, or at least in appendices, with an expectation that the workaround will eventually be obsolete. [Failure here implies that the resource interfaces are object-specific, not generic.]
REST API不应修改通讯协议中预留出来作为补充或修正标准协议用途的资源,例如HTTP的PATCH方法和Link head域。违背了这一原则的方案应当单独定义,或者至少在附录中标注出来这样的方案最终会废弃掉。[ 不符合这一点意味着资源接口是对象相关的,不通用 ]

A REST API should spend almost all of its descriptive effort in defining the media type(s) used for representing resources and driving application state, or in defining extended relation names and/or hypertext-enabled mark-up for existing standard media types. Any effort spent describing what methods to use on what URIs of interest should be entirely defined within the scope of the processing rules for a media type (and, in most cases, already defined by existing media types). [Failure here implies that out-of-band information is driving interaction instead of hypertext.]
REST API应当将绝大部分精力放在媒体类型的定义上,或者是扩展关系名称的定义、已有超文本标记中的标准媒体类型等方面,以实现资源的表述、操作应用程序状态。任何类似于对某某URI应当使用什么样的方法等工作,都应当完全定义在特定媒体类型的处理规则范围中(绝大部分情况下已有媒体类型都已经定义好了这些规则)。[ 不符合这一点意味着交互是由其它信息驱动,而不是超文本 ]

A REST API must not define fixed resource names or hierarchies (an obvious coupling of client and server). Servers must have the freedom to control their own namespace. Instead, allow servers to instruct clients on how to construct appropriate URIs, such as is done in HTML forms and URI templates, by defining those instructions within media types and link relations. [Failure here implies that clients are assuming a resource structure due to out-of band information, such as a domain-specific standard, which is the data-oriented equivalent to RPC's functional coupling].
REST API决不能定义固定的资源名称或者层次关系(这是明显的客户端、服务器端耦合),服务器必须可以自由控制自己的名称空间。应当像HTML forms和URI模板一样,通过媒体类型和链接关系指示客户端如何构造正确的URI。[ 不符合这一点意味着客户端在通过其它信息(例如领域相关标准)猜测资源结构,这是数据导向,类似于RPC的函数耦合 ]

A REST API should never have “typed” resources that are significant to the client. Specification authors may use resource types for describing server implementation behind the interface, but those types must be irrelevant and invisible to the client. The only types that are significant to a client are the current representation’s media type and standardized relation names. [ditto]
REST API决不能使用对客户端有重要意义的类型化资源。规范的作者可能使用资源类型描述接口背后的服务器端实现,但这些类型必须与客户端无关,对客户端不可见。对客户端唯一有意义的类型是当前的表述性媒体类型和标准的关系名称。[ 同上 ]

A REST API should be entered with no prior knowledge beyond the initial URI (bookmark) and set of standardized media types that are appropriate for the intended audience (i.e., expected to be understood by any client that might use the API). From that point on, all application state transitions must be driven by client selection of server-provided choices that are present in the received representations or implied by the user’s manipulation of those representations. The transitions may be determined (or limited by) the client’s knowledge of media types and resource communication mechanisms, both of which may be improved on-the-fly (e.g., code-on-demand). [Failure here implies that out-of-band information is driving interaction instead of hypertext.]

使用REST API应该只需要知道初始URI(书签)和一系列针对目标用户的标准媒体类型(任何客户端都了解用来操作该媒体类型的API)。这样所有的应用程序状态转换都通过这样的方式进行:服务器在返回的表述性消息中提供选项,由客户端进行选择,或者是伴随着用户对表述性内容的操作而进行。状态转换由客户端对媒体类型的了解程度和资源通讯机制决定,或者受限于这些因素,这些问题都可以根据实际情况得以改善的(例如使用javascript这种code-on-demand技术)。[ 不符合这一点意味着交互是由其它信息驱动,而不是超文本 ]

There are probably other rules that I am forgetting, but the above are the rules related to the hypertext constraint that are most often violated within so-called REST APIs. Please try to adhere to them or choose some other buzzword for your API.
也许还有其它一些规则我一时想不起来了,但在那些所谓的REST API中通常都违背了上面这些超文本约束相关的规则,请纠正这些错误或者改用其它称谓吧

程序的接口都明显的具备特定的目的,因此一上来可能就是请求特定的资源或者操作,但这就成了Roy T. Fielding理解的HTTP-based interface了
疑点之一:什么是typed resources、resource types、media types以及他们之间的区别
疑点之二:如何仅通过初始URI得到具体的资源,这样的REST API到底是什么样的一种形式?毕竟普通应用并不都是spider一样,通过root一路爬下去就行了
过几天再仔细看看原文回复讨论的内容

[翻译] REST API必须是超文本驱动的相关推荐

  1. python有道翻译接口-【Python】Python利用有道翻译开发API应用示例

    Python源码是关于Python利用有道翻译开发API应用示例.这是一个很有意思又简单的API应用练习题,方法中用到了有道词典开放API应用,合成的类似于命令行词典应用Python小程序.功能简单, ...

  2. python有道字典_【Python】Python利用有道翻译开发API应用示例

    Python源码是关于Python利用有道翻译开发API应用示例.这是一个很有意思又简单的API应用练习题,方法中用到了有道词典开放API应用,合成的类似于命令行词典应用Python小程序.功能简单, ...

  3. python微信公众号翻译功能_使用python在SAE上搭建一个微信应用,使用有道翻译的api进行在线翻译...

    1. 准备,先在使用python一步一步搭建微信公众平台(一)中基本实现自动回复的功能后,接着在有道词典上申请一个key,http://fanyi.youdao.com/openapi?path=da ...

  4. Python3 图片文字识别翻译——调用百度AI、百度翻译和有道翻译的API

    文章目录 Python3 图片文字识别翻译--调用百度AI.百度翻译和有道翻译的API 一.演示 二. API准备 三. 图片文字识别--调用百度AI文字识别API 四. 文字翻译 1. 百度翻译 请 ...

  5. android英文文献翻译,安卓 英文 外文 文献翻译 android api级别.doc

    安卓 英文 外文 文献翻译 android api级别.doc Android API Levels As you develop your application on Android, it s ...

  6. 把英文翻译成中文php,中文翻译成英文,英文翻译成中文(调用的有道翻译的api)示例源码...

    [实例简介] 调用的 有道翻译的api [实例截图] [核心代码] define("CURL_TIMEOUT", 20); define("URL", &quo ...

  7. 用java多线程实现“百度翻译接口API快速翻译”

    不知道为啥,突然开始想写博客,可能是想找个地方写点东西,煽情文艺的咱写不了,就写技术贴好了.不当之处,还希望同志们多多指教,不胜感激. API准备:自己先到百度去申请一个百度翻译API,话说百度翻译还 ...

  8. 百度翻译金山词霸API

    1 #/usr/bin/env python3 2 #coding=utf8 3 4 """百度翻译api功能实现函数,本模块基于Python3.x实现,getTrans ...

  9. c#语言程序翻译软件,百度翻译新API C#代码(winfrom,webform....)小程序-Go语言中文社区...

    3月的下午,在C#群里日常装逼(聊天), 一兄弟说百度翻译有没有winfrom上用的Demo,问了一天  嫌烦了  我就干脆自己写个: PS 百度上的部分代码害死人啊  api地址都换的不成样了, 还 ...

  10. 采用抓包的方式逆向获得谷歌翻译的API

    文章目录 最开始的尝试 2022.12.26 谷歌翻译API相关信息 发送网址 提交的数据 不过不出意外的失败了 实验 去掉参数 去掉Headers 代码 对返回结果进行解析 完整代码 最开始的尝试 ...

最新文章

  1. 关于jspsmartupload中的各种问题
  2. MySQL查询优化:LIMIT 1避免全表扫描
  3. XML解析,dom解析,Jdom解析
  4. Nobot控件------拒绝机器人行为
  5. 搭建集群负载均衡系统
  6. 【NOIP2013】【Luogu1969】积木大赛(贪心,差分)
  7. docker 代理_利用Docker容器实现代理转发和数据备份
  8. Pulseaudio调用alsalib open()流程(十五)
  9. Esxi遇到问题汇总。
  10. linux的一些目录结构
  11. matlab如何将二进制文件写入txt文档中
  12. java docx转pdf_在java中将docx转换为pdf
  13. 最受程序员 欢迎的14个社区
  14. 如何在Windows上启用JavaScript
  15. arm嵌入式系统C语言代码,ARM嵌入式系统C语言编程.pdf
  16. html制作学生信息表静态网页,实验一静态网页制作报告.doc
  17. 第六章——数值积分与数值微分
  18. PnetLab模拟器一键汉化教程
  19. openldap简介
  20. BA-中央空调冰蓄冷(视频)

热门文章

  1. 诺基亚x6升级android9体验,诺基亚X6手机怎么样?诺基亚X6全面详细评测
  2. 帆软报表嵌套在iframe中,HTML的fieldset 定义的为自定义导出按钮
  3. 七牛云 rs.php 没有,设置了callbackUrl,七牛只是在客户端上打印了json格式的key和hash,居然没有按照设置跳转回来..怎么弄?...
  4. 没有找到dllregisterserver输入点_「Mac实用技巧」将浏览器的点密码转换成文本密码的三种方法分享...
  5. Java重入函数_重入函数
  6. 从实例中学习grid布局
  7. Unity3D之Json序列化
  8. ASP.NET 性能监控工具和优化技巧
  9. ORA-04031:unable to allocate 4120 bytes of shared memory ‘obj stat mem’故障解决
  10. Mac 显示和隐藏文件