Skip to content

1.5.0

Choose a tag to compare

@koriym koriym released this 19 May 21:25
· 1726 commits to 1.x since this release
  • [ADD] RFC 2616 OPTIONS method payload #95 #99
  • [ADD] OptionsMethodModule #96
  • [ADD] @ResourceParam template URI support #97
  • [ADD] http constant package koriym/http-constant
  • [FIX] Disallow @ResourceParam and @assisted parameter by withQuery() query #98

RFC 2616 - HTTP/1.1 specification section 9.2 page 51 OPTIONS

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.

The payload of OPTIONS method is generated from method signature and PHPDOC. You would not need extra work to provide specifications.

    /**
     * Todos list
     *
     * Returns the todos list specified by status
     *
     * @param string $status todo status
     */
    public function onGet(string $status = null) : ResourceObject
    {
        // ....
    }

    /**
     * Create todo
     *
     * Create todo and add to todos list
     *
     * @param string $title todo title
     *
     */    
    public function onPost(string $title) : ResourceObject
    {
        // ....
    }

The result of http OPTIONS method request.

curl -i -X OPTIONS http://127.0.0.1:8080/

HTTP/1.1 200 OK
Host: 127.0.0.1:8080
Date: Tue, 16 May 2017 03:48:50 +0200
Connection: close
X-Powered-By: PHP/7.1.0
Content-Type: application/json
allow: GET, POST

200 OK
Content-Type: application/json
allow: GET, POST

{
    "GET": {
        "summary": "Todos list",
        "description": "Returns the todos list specified by status",
        "parameters": {
            "status": {
                "description": "todo status",
                "type": "string"
            }
        }
    },
    "POST": {
        "summary": "Create todo",
        "description": "Create todo and add to todos list",
        "parameters": {
            "title": {
                "description": "todo title",
                "type": "string"
            }
        },
        "required": [
            "title"
        ]
    }
}

An options command works in console as well as web.

php bootstrap/web.php options /

200 OK
Content-Type: application/json
allow: GET, POST

{
    "GET": {

@ResourceParam supports uri template.

The result of resource request app://self/rparam/login{?name}#nickname is injected to theid parameter.

    /**
     * @ResourceParam(param="id", uri="app://self/rparam/login{?name}#nickname", templated=true)
     */
    public function onPost($id, $name)
    {