- 浏览: 184390 次
- 性别:
- 来自: 北京
最新评论
-
angjunwen:
^[1-9]\d*|0$ 这个能处理小数吗?
ruby on rails 常用正则表达式 -
hot88zh:
Hooopo 写道为什么这么多踩的呢 呃。。还真是,你不说我都 ...
Ruby如何用Oauth与第三方网站互动 -
Hooopo:
为什么这么多踩的呢
Ruby如何用Oauth与第三方网站互动 -
robbinwork:
顶
改良程序的11技巧 -
rogerer:
请问ROR上传大文件,怎么解决内存占用问题:1. lightt ...
查询rails的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.
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?
API designers, please note the following rules before calling your creation a 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.]
- 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.]
- 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.]
- 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].
- 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]
- 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.]
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.
发表评论
-
linux下进入rails console提示cannot load such file -- readline
2011-12-17 20:38 2809在linux下输入rails console,之后提示错误,如 ... -
在Windows7中编译Mysql2的GEM
2011-11-08 15:47 0If you still want to force t ... -
CentOS用gem安装Mysql2提示缺少mysql.h
2011-08-30 12:17 2892环境: CentOS6 Ruby1.9.2 Rails3.0. ... -
Rake提示uninitialized constant Rake::DSL解决办法
2011-06-20 00:09 3709环境:Ruby 1.9.1/Rails 3.0.9/Rake ... -
Debian5安装Thin时候出现no such file to load -- openssl
2011-04-19 22:38 1134今天在执行thin install的时候,出现no such ... -
oauth GEM的几个小例子
2011-03-22 08:32 15981、注册并认证你的应用 #!/usr/bin/r ... -
Ruby如何用Oauth与第三方网站互动
2011-03-13 12:25 2087首先是介绍一下这个gem:oauth 项目首页是:http: ... -
升级gem提示缺少no such file to load zlib
2011-02-20 01:16 1368升级gem提示 no such file to load zl ... -
使用Ruby解析图片EXIF数据获取坐标信息
2011-01-10 08:32 1822最近在做一个项目时需要将图片EXIF信息解析出来并获取相应 ... -
Paperclip提示command is not recognized by the 'identify
2011-01-05 00:43 2312用Paperclip来裁减图片,会提示如下错误: /tmp/ ... -
在Debian上部署Ruby On Rails应用(续)
2011-01-05 00:36 1279写在前面: 其实这个续应该和前面那个部署的文章互换一下顺序… ... -
Ruby1.9.2+Rails3.0.3迁移文件中加索引出错的解决办法
2011-01-03 23:53 1555环境: Ruby1.9.2 Rails3.0.3 Gem ... -
rails3使用declarative_authorization注意事项
2010-11-17 17:32 1238Rails3中把declarative_authorizati ... -
rails3使用restful-authentication
2010-11-09 14:01 2041首先要下载支持Rails3的restful-authentic ... -
Ubuntu安装Mysql Gem
2010-11-03 14:49 1328在安装过程中出现如下错误: Building native e ... -
如何寫出有效率的 Ruby Code
2010-09-28 22:44 1025Instance Variables versus Acces ... -
Rails Migration Data Types – MySql – Postgresql – SQLite
2010-06-04 19:09 1229Rails mysql post ... -
request.env
2009-11-11 13:16 1161@client_ip = request.env[" ... -
Active Record Validations and Callbacks
2009-11-08 22:39 2051有许多种在保存数据到 ... -
Ruby on Rails 的检验方法(Validation Helpers)大全
2009-11-06 12:07 1444可以自定义validate(), 这个方法在每次保存数据时都会 ...
评论