Skip to content

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

Closed
@khaliddermoumi

Description

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

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions