RESTful API methods; HEAD & OPTIONS

后端 未结 3 576
一生所求
一生所求 2020-12-07 13:11

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

3条回答
  •  借酒劲吻你
    2020-12-07 13:33

    OPTIONS method returns info about API (methods/content type)

    HEAD method returns info about resource (version/length/type)

    Server response

    OPTIONS

    HTTP/1.1 200 OK
    Allow: GET,HEAD,POST,OPTIONS,TRACE
    Content-Type: text/html; charset=UTF-8
    Date: Wed, 08 May 2013 10:24:43 GMT
    Content-Length: 0
    

    HEAD

    HTTP/1.1 200 OK
    Accept-Ranges: bytes
    Content-Type: text/html; charset=UTF-8
    Date: Wed, 08 May 2013 10:12:29 GMT
    ETag: "780602-4f6-4db31b2978ec0"
    Last-Modified: Thu, 25 Apr 2013 16:13:23 GMT
    Content-Length: 1270
    
    • OPTIONS Identifying which HTTP methods a resource supports, e.g. can we DELETE it or update it via a PUT?
    • HEAD Checking whether a resource has changed. This is useful when maintaining a cached version of a resource
    • HEAD Retrieving metadata about the resource, e.g. its media type or its size, before making a possibly costly retrieval
    • HEAD, OPTIONS Testing whether a resource exists and is accessible. For example, validating user-submitted links in an application

    Here is nice and concise article about how HEAD and OPTIONS fit into RESTful architecture.

提交回复
热议问题