Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OPTIONS method payload #95

Merged
merged 33 commits into from
May 16, 2017
Merged

OPTIONS method payload #95

merged 33 commits into from
May 16, 2017

Conversation

koriym
Copy link
Member

@koriym koriym commented May 5, 2017

OPTIONS method returns Allow methods in response header as well as more information for resource request in payload. Information are generated from ReflectionParameter and phpdoc inculdes @params.

PHPDOC

    /**
     * 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": {

Related information:

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 HTTP/1.1 specification section 9.2 page 51, describe the OPTIONS method, and in part states that when a request using the OPTIONS method on a specific resource is made:
The response body, if any, SHOULD also include information about the communication options

http://discuss.jsonapi.org/t/rfc-standardising-an-options-response-on-a-server-that-supports-jsonapi/407/21

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).

http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven

@koriym koriym merged commit 4683b33 into bearsunday:1.x May 16, 2017
@koriym koriym deleted the method branch May 16, 2017 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant