转:REST API必须是超文本驱动的

本文探讨了当前许多基于HTTP的接口被误称为REST API的问题,并详细解释了REST API的设计原则,包括独立于通信协议、避免固定资源名称、由超文本驱动交互等方面。

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一路爬下去就行了

过几天再仔细看看原文回复讨论的内容

同步定位与地图构建(SLAM)技术为移动机器人或自主载具在未知空间中的导航提供了核心支撑。借助该技术,机器人能够在探索过程中实时构建环境地图并确定自身位置。典型的SLAM流程涵盖传感器数据采集、数据处理、状态估计及地图生成等环节,其核心挑战在于有效处理定位与环境建模中的各类不确定性。 Matlab作为工程计算与数据可视化领域广泛应用的数学软件,具备丰富的内置函数与专用工具箱,尤其适用于算法开发与仿真验证。在SLAM研究方面,Matlab可用于模拟传感器输出、实现定位建图算法,并进行系统性能评估。其仿真环境能显著降低实验成本,加速算法开发与验证周期。 本次“SLAM-基于Matlab的同步定位与建图仿真实践项目”通过Matlab平台完整再现了SLAM的关键流程,包括数据采集、滤波估计、特征提取、数据关联与地图更新等核心模块。该项目不仅呈现了SLAM技术的实际应用场景,更为机器人导航与自主移动领域的研究人员提供了系统的实践参考。 项目涉及的核心技术要点主要包括:传感器模型(如激光雷达与视觉传感器)的建立与应用、特征匹配与数据关联方法、滤波器设计(如扩展卡尔曼滤波与粒子滤波)、图优化框架(如GTSAM与Ceres Solver)以及路径规划与避障策略。通过项目实践,参与者可深入掌握SLAM算法的实现原理,并提升相关算法的设计与调试能力。 该项目同时注重理论向工程实践的化,为机器人技术领域的学习者提供了宝贵的实操经验。Matlab仿真环境将复杂的技术问题可视化与可操作化,显著降低了学习门槛,提升了学习效率与质量。 实践过程中,学习者将直面SLAM技术在实际应用中遇到的典型问题,包括传感器误差补偿、动态环境下的建图定位挑战以及计算资源优化等。这些问题的解决对推动SLAM技术的产业化应用具有重要价值。 SLAM技术在工业自动化、服务机器人、自动驾驶及无人机等领域的应用前景广阔。掌握该项技术不仅有助于提升个人专业能力,也为相关行业的技术发展提供了重要支撑。随着技术进步与应用场景的持续拓展,SLAM技术的重要性将日益凸显。 本实践项目作为综合性学习资源,为机器人技术领域的专业人员提供了深入研习SLAM技术的实践平台。通过Matlab这一高效工具,参与者能够直观理解SLAM的实现过程,掌握关键算法,并将理论知识系统应用于实际工程问题的解决之中。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值