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

Deal with (optional) headers #39

Closed
MichielDeMey opened this issue Feb 22, 2015 · 6 comments
Closed

Deal with (optional) headers #39

MichielDeMey opened this issue Feb 22, 2015 · 6 comments

Comments

@MichielDeMey
Copy link

Let's try and start a discussion about (optional) headers.

In my use-case, you have to specify your language through the Accept-Language header and depending on the selected language, the response is different.

+ Request
    + Header
            Accept-Language: en-US

+ Response 200 (application/json)
    // English response

+ Request
    + Header
            Accept-Language: nl-BE

+ Response 200 (application/json)
    // Dutch response

One thing I noticed however is that drakov will return a 404 if the header doesn't match the one specified in the blueprint. However, in my API the Accept-Language header is optional and will default to en-US if undefined.

Let's discuss two things:

  • Separate responses for different headers
  • Replying with the default (first) response when the header is not present.
  • Define which headers could be optional (by default) and allow an option to define which headers should be optional
@yakovkhalinsky
Copy link
Contributor

@MichielDeMey I've had a brief discussion with my colleagues about this and we feel that making the header matching less strict would complicate the rules around response/request pair matching.

I think that being specific with the headers allows you to get a more predictable response from Drakov.

@MichielDeMey
Copy link
Author

Makes sense, however, does Drakov currently support use-case 1 (example suplied)?

In that case I can define a response without an active header and treat that as the default response.

@yakovkhalinsky
Copy link
Contributor

Yep, absolutely.

We have a test Blueprint file we test against to ensure behaviours against headers:
https://github.com/Aconex/drakov/blob/master/test/example/md/headers.md

Let me know if you have any trouble with the headers 👍

@MichielDeMey
Copy link
Author

Just tested this, works as expected. :)
Simply specifying a response without a header will treat it as the default response in case a header is not present.

@alexborisov
Copy link

Just a quick thought, but would it not make sense to at least return something besides a 404? Technically the resource IS found, it's just the request was incorrect...

@oklaiss-gpsw
Copy link

Returning something other than a 404 would be a lot more useful, simply getting 404's back doesn't provide any useful information about what is actually wrong.

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

No branches or pull requests

4 participants