基于REST的API方法; HEAD&安培; OPTIONS [英] RESTful API methods; HEAD & OPTIONS

查看:251
本文介绍了基于REST的API方法; HEAD&安培; OPTIONS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写在PHP应用程序一个RESTful API模块,和我有点混合的动词 HEAD 选项

I'm writing a RESTful API module for an application in PHP, and I'm a bit mixed on the verbs HEAD and OPTIONS.


      
  • 选项用于检索可用的HTTP动词给定资源?

  •   
  • HEAD 用于确定给定的资源是否可用?

  •   
  • OPTIONS  Used to retrieve the available HTTP verbs for a given resource?
  • HEAD Used to determine whether a given resource is available?

如果有人能澄清*这些动词,那会是多少AP preciated。

If someone could clarify* these verbs, that would be much appreciated.

<子> *澄清了关于REST的API架构,再重新考虑HTTP动词。我既然来实现这两个 HEAD 选项应的的重新-purposed,而是pdictably行为$ p $应该作为任何HTTP应用程序。呵呵,怎么我们成长在2年。

* The clarification was with respect to RESTful API architectures re-purposing HTTP verbs. I've since come to the realization that both HEAD and OPTIONS should not be re-purposed, and instead behave predictably as any HTTP application should. Oh, how we grow in 2 years.

推荐答案

按<一个href=\"http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html\">http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html

9.2选项

选项方法再presents有关在由Request-URI标识的请求/响应链中可用的通信选项信息的请求。此方法允许客户端来确定的选项和/或与资源相关​​联的要求,或者一个服务器的能力,而不意味着资源操作或发起资源检索。

The OPTIONS method represents a request for information about the communication options available on the request/response chain identified by the Request-URI. This method allows the client to determine the options and/or requirements associated with a resource, or the capabilities of a server, without implying a resource action or initiating a resource retrieval.

该方法的响应不能缓存。

Responses to this method are not cacheable.

如果OPTIONS请求包括实体主体(由内容长度或传输编码的presence所示),那么媒体类型必须是内容类型字段中指示。虽然这个规范没有定义这样一个机构的任何使用,将来HTTP扩展可能使用OPTIONS身体,使服务器的更多详细的查询。不支持这样的扩展服务器可以丢弃该请求主体。

If the OPTIONS request includes an entity-body (as indicated by the presence of Content-Length or Transfer-Encoding), then the media type MUST be indicated by a Content-Type field. Although this specification does not define any use for such a body, future extensions to HTTP might use the OPTIONS body to make more detailed queries on the server. A server that does not support such an extension MAY discard the request body.

如果请求URI是一个星号(),OPTIONS请求旨在应用于服务器一般而不是一个特定的资源。自服务器的通信选择通常取决于资源,在的请求是仅作为一个ping或空操作类型的方法的有用它什么都不超出允许客户端测试的服务器的能力。例如,这可以用于测试的HTTP / 1.1顺应性(或缺乏)的代理。

If the Request-URI is an asterisk (""), the OPTIONS request is intended to apply to the server in general rather than to a specific resource. Since a server's communication options typically depend on the resource, the "" request is only useful as a "ping" or "no-op" type of method; it does nothing beyond allowing the client to test the capabilities of the server. For example, this can be used to test a proxy for HTTP/1.1 compliance (or lack thereof).

如果请求URI不是一个星号,OPTIONS请求只适用于与资源进行通信时可用的选项。

If the Request-URI is not an asterisk, the OPTIONS request applies only to the options that are available when communicating with that resource.

一个200响应应该包含任何头字段指示由服务器,适用于该资源实现的可选功能(例如,允许),可能包括不是本规范定义的扩展。响应体,如果有的话,还应包括有关通信选项的信息。对于这样一个机构的格式不被本说明书中定义的,但可能是由于HTTP将来扩展来限定。内容协商可能被用于选择适当的响应格式。如果不包含响应体,则响应必须包括的域值一个Content-Length字段为0。

A 200 response SHOULD include any header fields that indicate optional features implemented by the server and applicable to that resource (e.g., Allow), possibly including extensions not defined by this specification. The response body, if any, SHOULD also include information about the communication options. The format for such a body is not defined by this specification, but might be defined by future extensions to HTTP. Content negotiation MAY be used to select the appropriate response format. If no response body is included, the response MUST include a Content-Length field with a field-value of "0".

马克斯-Forwards请求头域可能被用于针对请求链中的一个特定的代理。当代理收到该请求转发允许在一个绝对URI的OPTIONS请求,代理必须检查出现的Max-Forwards域。如果最大-Forwards域值是零(0),proxy不能转发信息;相反,代理应该有自己的通信选项做出回应。如果最大-Forwards域值是大于零的整数,当它把请求转发代理必须递减域值。如果没有的Max-Forwards域是在请求present,则转发的请求不能包含的Max-Forwards域。

The Max-Forwards request-header field MAY be used to target a specific proxy in the request chain. When a proxy receives an OPTIONS request on an absoluteURI for which request forwarding is permitted, the proxy MUST check for a Max-Forwards field. If the Max-Forwards field-value is zero ("0"), the proxy MUST NOT forward the message; instead, the proxy SHOULD respond with its own communication options. If the Max-Forwards field-value is an integer greater than zero, the proxy MUST decrement the field-value when it forwards the request. If no Max-Forwards field is present in the request, then the forwarded request MUST NOT include a Max-Forwards field.

9.4 HEAD

HEAD方法是相同的,只是在响应服务器不能返回一个消息体得到的。在响应于一个HEAD请求中包含的HTTP标题的元信息应该是相同的,以响应于GET请求发送的信息。该方法可用于获得关于不转移实体本身由该请求中隐含的实体的元信息。此方法通常用于有效性,可访问性,和最近的修改测试的超级文本链接。

The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response. The metainformation contained in the HTTP headers in response to a HEAD request SHOULD be identical to the information sent in response to a GET request. This method can be used for obtaining metainformation about the entity implied by the request without transferring the entity-body itself. This method is often used for testing hypertext links for validity, accessibility, and recent modification.

要HEAD请求的响应可以在这个意义上高速缓存包含在响应中的信息可以被用于更新一个previously从该资源高速缓存的实体。如果新的字段值表明该高速缓存的实体从当前实体的不同(如将在内容长度,内容-MD5 ETag的或上次修改的改变来指示),则该高速缓存必须把高速缓存条目为失效。

The response to a HEAD request MAY be cacheable in the sense that the information contained in the response MAY be used to update a previously cached entity from that resource. If the new field values indicate that the cached entity differs from the current entity (as would be indicated by a change in Content-Length, Content-MD5, ETag or Last-Modified), then the cache MUST treat the cache entry as stale.

这篇关于基于REST的API方法; HEAD&安培; OPTIONS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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