REST架构的核心属性之一便是统一接口,可现在的HTML表单只支持GET和POST方法,一下子就“禁掉”(但是还是可以通过JavaScript脚本实现其它接口)了REST要求的一半接口。《RESTful Web Services》中很多例子都给form的method赋上了PUT、DELETE值,说是HTML5中会支持。于是我就好奇地搜了下HTML5在这方面的内容。
在w3.org上的HTML5仓库里看到了一篇《HTML5 differences from HTML4》,是今年三月10号发布的草案。简单的用Ctrl-F搜了下“ form ”关键字,好像并没有提到改进了method方法,form的属性改动不少,但就是没有method啊……于是就疑惑了,难道用PUT和DELETE还得写JS?
文章发布得冲动了……刚才翻看了最新的HTML5草案,看到了这段话:
The method
and formmethod
content attributes are enumerated attributes with the following keywords and states:
- The keyword
GET
, mapping to the state GET, indicating the HTTP GET method. - The keyword
POST
, mapping to the state POST, indicating the HTTP POST method. - The keyword
PUT
, mapping to the state PUT, indicating the HTTP PUT method. - The keyword
DELETE
, mapping to the state DELETE, indicating the HTTP DELETE method.
The missing value default for these attributes is the GET state.
The method of an element is one of those four states. If the element is a submit button and has a formmethod
attribute, then the element's methodis that attribute's state; otherwise, it is the form owner's method
attribute's state.
为什么那篇differences就不提呢……