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

Problem getting different responses with "Prefer: status=xxx" header #88

Closed
khaliddermoumi opened this issue Sep 9, 2015 · 5 comments
Closed
Labels

Comments

@khaliddermoumi
Copy link
Contributor

I have a problem getting different responses using the "Prefer"-header.

In the FAQ, it says: "You can request a specific response by adding a Prefer header to the request in the form Prefer:status=XXX where XXX is the status code of the desired response."
I have tried that and can't get it to work.
I have a blueprint with a PUT-action, that has 2 responses defined:

### Update Something[PUT]
Updates something.

+ Request (application/json)

    + Headers

            Authorization: Bearer e2Rlc2NyaXB0aW9uOiB0aGlzIGlzIGFuIGFjY2VzcyB0b2tlbn0=

    + Body

            {
                "uniqueId": "ec58279d79f242189d153f575a8b9df0",
                "timestamp": "2015-04-06T10:01:12",
                "subject": "ACME Corp."
            }

+ Response 200 (application/vnd.siren+json)

        {
            "class": [ "something" ],
            "properties": {
                "uniqueId": "ec58279d79f242189d153f575a8b9df0",
                "timestamp": "2015-04-06T10:01:12",
                "subject": "ACME Corp."
            },
            "links": [
                { "rel": [ "self" ], "href": "https://localhost:3000/something/ec58279d79f242189d153f575a8b9df0" }
            ],
            "actions": [
                { "name": "update-something", "title": "Update Something", "method": "PUT", "href": "https://localhost:3000/something/ec58279d79f242189d153f575a8b9df0" }
            ]
        }

+ Response 409 (application/problem+json)

        {
            "type": "some error",
            "title": "There is an update conflict",
            "detail": "The resource could not be updated, because it is based on an older version that was updated meanwhile. Get the new version, merge your data, and retry the update."
        }

Now, when I call using curl, drakov properly returns the "200" response (as expected):

curl --cacert certificates/ia.crt \
    --header "Authorization: Bearer e2Rlc2NyaXB0aW9uOiB0aGlzIGlzIGFuIGFjY2VzcyB0b2tlbn0=" \
    --header "Content-Type: application/json" \
    --request PUT \
    --data '{
                "uniqueId": "ec58279d79f242189d153f575a8b9df0",
                "timestamp": "2015-04-06T10:01:12",
                "subject": "ACME Corp."
            }' \
    https://localhost:3000/something/ec58279d79f242189d153f575a8b9df0

But, when I add the "Prefer"-header (as documented), drakov does not return the "409" response, but says "cannot PUT":

curl --cacert certificates/ia.crt \
    --header "Authorization: Bearer e2Rlc2NyaXB0aW9uOiB0aGlzIGlzIGFuIGFjY2VzcyB0b2tlbn0=" \
    --header "Content-Type: application/json" \
    --header "Prefer:status=409" \
    --request PUT \
    --data '{
                "uniqueId": "ec58279d79f242189d153f575a8b9df0",
                "timestamp": "2015-04-06T10:01:12",
                "subject": "ACME Corp."
            }' \
    https://localhost:3000/something/ec58279d79f242189d153f575a8b9df0

-> Response is:
Cannot PUT /something/ec58279d79f242189d153f575a8b9df0

Any hints what is wrong?

BTW: thx a lot for drakov!

Regards,
Khalid

@yakovkhalinsky
Copy link
Contributor

hey @khaliddermoumi thanks for your question, I'll have a look at this over the next day and get back to you 👍

@yakovkhalinsky
Copy link
Contributor

I can see while debugging that the content type isn't being matched for your 409 prefer header request.

I'll investigate this and hopefully get a fix in for tomorrow 👍

Thanks again for reporting this

@khaliddermoumi
Copy link
Contributor Author

Thanks Yakov!

@yakovkhalinsky
Copy link
Contributor

OK so, I've spent some time looking at this, what Drakov expects is a collection of request/response pairs.

Since your 409 doesn't have a request, there's no content-type, headers or schema/body to make that pair a match.

You could either copy the request into the 409 section or use a schema like so:

FORMAT: 1A

# Return something
Do something

## Something [/something]

### Update Something[PUT]
Updates something.

+ Request (application/json)

    + Headers

            Authorization: Bearer e2Rlc2NyaXB0aW9uOiB0aGlzIGlzIGFuIGFjY2VzcyB0b2tlbn0=

    + Body

            {
                "uniqueId": "ec58279d79f242189d153f575a8b9df0",
                "timestamp": "2015-04-06T10:01:12",
                "subject": "ACME Corp."
            }

+ Response 200 (application/vnd.siren+json)

        {
            "class": [ "something" ],
            "properties": {
                "uniqueId": "ec58279d79f242189d153f575a8b9df0",
                "timestamp": "2015-04-06T10:01:12",
                "subject": "ACME Corp."
            },
            "links": [
                { "rel": [ "self" ], "href": "https://localhost:3000/something/ec58279d79f242189d153f575a8b9df0" }
            ],
            "actions": [
                { "name": "update-something", "title": "Update Something", "method": "PUT", "href": "https://localhost:3000/something/ec58279d79f242189d153f575a8b9df0" }
            ]
        }

+ Request (application/json)

    + Headers

            Authorization: Bearer e2Rlc2NyaXB0aW9uOiB0aGlzIGlzIGFuIGFjY2VzcyB0b2tlbn0=

    + Schema
            {
                "type": "object",
                "properties": {
                    "uniqueId": {"type": "string"},
                    "timestamp": {"type": "string" },
                    "subject": {"type": "string" }
                }
            }

+ Response 409 (application/problem+json)

        {
            "type": "some error",
            "title": "There is an update conflict",
            "detail": "The resource could not be updated, because it is based on an older version that was updated meanwhile. Get the new version, merge your data, and retry the update."
        }

@khaliddermoumi
Copy link
Contributor Author

Thanks for your investigation, Yakov!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants