Skip to content

Content negotiation redux #703

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

Merged
merged 3 commits into from
May 28, 2015
Merged

Content negotiation redux #703

merged 3 commits into from
May 28, 2015

Conversation

dgeb
Copy link
Member

@dgeb dgeb commented May 27, 2015

This is a refinement of @ethanresnick's work in #673. It separates the client and server responsibilities for clarity and corrects a few aspects.

I won't attempt to summarize the tweaks. It's important to review the full text carefully.

…nces of violating them

See rationale in #673. Also consolidates all the rules into the content
negotiation section.
@tkellen
Copy link
Member

tkellen commented May 27, 2015

👍

@dgeb dgeb added this to the 1.0 milestone May 27, 2015
@ethanresnick
Copy link
Member

Thanks for working on these refinements, @dgeb! I'm excited to get this text in too!

👍 On dividing client and server responsibilities, and on some of your rewordings, which made things far less awkward.

👎 On the sentence "Servers MUST respond with a 406 Not Acceptable status code if a request's Accept header doesn't contain any media types that the server can produce." Again, this is us being more prescriptive than HTTP itself, and feels like stepping out of bounds to me.

👎 On removing the non-normative note about serving JSON API as JSON. I added that because a good server should support this, to make it easier for developers to make requests using generic clients (like curl) without having to go to the (totally unnecessary) trouble of setting a custom Accept header. Responding with JSON as a fallback also just generally makes the API more robust.

Of course, you guys have the final call on all this, but that's my .02

@tkellen
Copy link
Member

tkellen commented May 27, 2015

Okay, the curl example has convinced me. I think you're right RE: fallbacks @ethanresnick.

@ethanresnick
Copy link
Member

@tkellen Cool! :)

Credit where it's due, though: the idea for the note originally goes back to #518.

@dgeb
Copy link
Member Author

dgeb commented May 28, 2015

If we remove this statement: "Servers MUST respond with a 406 Not Acceptable status code if a request's Accept header doesn't contain any media types that the server can produce."

Then we remove the ability for clients / servers to negotiate based on media type parameters in the future.

@dgeb
Copy link
Member Author

dgeb commented May 28, 2015

This is why I specifically called out the ext parameter in the current section on media type negotiation: http://jsonapi.org/format/#media-type-negotiation

@dgeb
Copy link
Member Author

dgeb commented May 28, 2015

This is awkwardly worded, but provides the allowance we need while (I think) respecting @ethanresnick's concerns about overstepping ourbounds:

Servers MUST respond with a 406 Not Acceptable status code if a request's Accept header contains the JSON API media type and the only instances of that media type are modified with media type parameters.

@ethanresnick
Copy link
Member

@dgeb Your reworded clause works for me!

Also, sorry, I should've been clearer originally. I was imagining that, if we removed the sentence, extension negotiation would still work because the client would check the Content-Type of the response to know if the contract has been established successfully. If it got JSON-API content back (eventually, with the extension parameters), things worked; if it got another content type, or a 406, then negotiation has failed.

The theoretical advantage of this would have been that it preserves the flexibility that HTTP allows for responding to a request like:

GET /articles
Accept: text/plain

With:

200 OK
Content-Type: application/json
{
   "data": { //... }
}

Rather than a 406.

Also, my thinking was that clients would have to inspect Content-Type in some cases anyway (and not just rely on status codes) to determine the result of negotiation—as when they say they'll support multiple (combinations of) extensions and they need to know which (combination) was chosen—so it wouldn't be too painful to make them always check that field.

That said, if we can give status code indicators, I think we should, and your new clause seems to let us do that while keeping all of HTTP's allowed wiggle room

@dgeb dgeb force-pushed the content-negotiation-redux branch from fd09819 to f39ebdd Compare May 28, 2015 02:46
@dgeb
Copy link
Member Author

dgeb commented May 28, 2015

@ethanresnick thanks for confirming! I've pushed the reworded clause.

Let's try to get something non-normative in tomorrow that will scratch your itch regarding working with generic clients.

request. Servers **MUST** ignore all other parameters for the
`application/vnd.api+json` media type in `Accept` and `Content-Type`
headers.
Servers **MUST** respond with a `406 Not Acceptable` status code if a
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about

Servers MUST respond with a 406 Not Acceptable status code when a request's Accept header contains the JSON API media type and all instances of that media type are modified with media type parameters.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@dgeb dgeb force-pushed the content-negotiation-redux branch from f39ebdd to 0b658e1 Compare May 28, 2015 12:35
@tkellen
Copy link
Member

tkellen commented May 28, 2015

Thanks for re-working this @dgeb. I'm 👍 to merge with that minor change.

tkellen pushed a commit that referenced this pull request May 28, 2015
@tkellen tkellen merged commit 8855778 into gh-pages May 28, 2015
@tkellen tkellen deleted the content-negotiation-redux branch May 28, 2015 12:36
@dgeb
Copy link
Member Author

dgeb commented May 28, 2015

Thanks for the careful review @ethanresnick and @tkellen!

@ethanresnick
Copy link
Member

@dgeb Absolutely!

Btw, as far as adding the non-normative note about serving application/json goes: let me know you want me to take another stab at that and, if so, whether there's anything in particular that should change from my prior version beyond general concision. Otherwise, if it's easier for you to just write something up yourself, that's fine too.

@dgeb
Copy link
Member Author

dgeb commented May 28, 2015

@ethanresnick Thanks - I'll definitely review your non-normative note again now that the normative changes have been merged.

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.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy