Skip to content

Media type negotiation cleanup #673

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

Conversation

ethanresnick
Copy link
Member

This does a few things:

  1. It doesn't let the server silently ignore media type parameters other than ext. Instead, it requires the server to explicitly return an error. We could add all sorts of parameters down the line, and post 1.0–clients that use these parameters may need to know whether they've been honored or not; silent ignoring could be quite unacceptable. By contrast, if we add any parameters down the line that can be simply ignored by old servers, then the post 1.0–client that gets the explicit error can simply retry its request without the parameter. (Of course, none of this effects 1.0 clients, since they're not allowed to include any parameters And, if they do, it's probably a bug, so an explicit error is more helpful for them too.)
  2. It applies the same treatment to ext as it does to every other media type parameter—namely, it requires the server to send the error mentioned in (1). This is better than using 406/415 here now, which will make it harder, when we add extensions in the future, for clients to distinguish between extensions not being supported at all vs. a particular extension not being supported. Also, there's no guarantee that we'll stick only to the ext parameter for required extension negotiation. (My proposal in Extensions Overhaul #650, for example, will, when I finish the last section, have an ext and a required-profile parameter.)
  3. It accounts for the fact that the Accept header can take multiple values, e.g. Accept: application/vnd.api+json;ext=bulk, application/vnd.api+json, and that the header is only problematic if every JSON-API option it lists contains parameters. If only some of the options contain parameters (as in the prior example), then the requests should succeed—and, in fact, future clients may want to format their Accept header like this to work with older servers.
  4. Update It also moves the remaining stray note about content negotiation that was in the "Fetching Data" section into this single top section. And it renames the section to "Content Negotiation", which is what everyone else calls this process, so we should too.
  5. Update: Finally, it reworks the requirements that were in "Fetching Data" to be more consistent with my understanding of our intentions. See my inline comments

@@ -34,20 +34,21 @@ the header `Content-Type: application/vnd.api+json`.
Clients **MUST** ignore all parameters for the `application/vnd.api+json`
media type received in the `Content-Type` header of response documents.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm thinking this paragraph could perhaps be deleted.

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought that too for a while. But I decided to leave it because we might, in the future, want to let the server to automatically opt the client in to some parameters (e.g. profile, which just adds extra semantics) and, if we do that, we don't want old clients to blow up.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, obviously clients are not permitted to blow up in the face of unexpected parameters. I just thought that would be... well, obvious. Maybe it's indeed better to leave this intact just in case.

However, right now the paragraph is right between the two requirements to which "either of the requirements above" is intended to refer, so you may want to consider moving it to the very end or explicitly mentioning "request requirements above" or something like that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, I reordered the paragraphs a bit. Let me know what you think, and thanks always for your close readings!

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it reads much better now 👍

@bintoro
Copy link
Contributor

bintoro commented May 23, 2015

Some API providers like to supply version information as a media type parameter, so let's be mindful of the fact that such a practice will now be disallowed unless a provision is made for it in these requirements.

@ethanresnick
Copy link
Member Author

Some API providers like to supply version information as a media type parameter, so let's be mindful of the fact that such a practice will now be disallowed.

True. Are you saying we should have a non-normative note somewhere pointing this out to people, or make an exception for a version parameter?

@bintoro
Copy link
Contributor

bintoro commented May 23, 2015

True. Are you saying we should have a non-normative note somewhere pointing this out to people, or make an exception for a version parameter?

The latter. Not saying we necessarily should, but if we want to accommodate the use case, I think it would be a reasonable provision to reserve something like api-version, or maybe api-*, for private use.

@@ -592,16 +602,6 @@ The following characters **MUST NOT** be used in member names:
Data, including resources and relationships, can be fetched by sending a
`GET` request to an endpoint.

Clients **MUST** indicate that they can accept the JSON API media type, per
Copy link
Member Author

Choose a reason for hiding this comment

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

Rather than saying that "Clients MUST indicate that they can accept the JSON API media type", I'm saying above that "Servers MUST NOT send responses with the application/vnd.api+json media type if the client has not indicated...it can understand this format." This seems to get at what we want—namely, you must ask for JSON API data in order to get it—while giving clients the freedom to ask for the other representations that, as our non-normative note alluded to, can exist at the same endpoint.

@ethanresnick ethanresnick force-pushed the media-type-negotiation-cleanup branch from 0ab8a2d to 323aaa4 Compare May 27, 2015 00:37
@ethanresnick
Copy link
Member Author

@dgeb Ok, I removed the detailed error href, made the note about returning json api as json non-normative, and added 406/415 cases!

@ethanresnick ethanresnick force-pushed the media-type-negotiation-cleanup branch 2 times, most recently from c3bca68 to 746639e Compare May 27, 2015 00:43
@dgeb
Copy link
Member

dgeb commented May 27, 2015

@ethanresnick thanks!

Would you mind squashing these commits down to one, or perhaps a few logical ones. I'd prefer to keep the history sane and free of additions that are removed in the same PR.

@ethanresnick ethanresnick force-pushed the media-type-negotiation-cleanup branch from 746639e to a6a051c Compare May 27, 2015 02:06
@ethanresnick
Copy link
Member Author

@dgeb Done!

@dgeb dgeb added this to the 1.0 milestone May 27, 2015

> Note: These requirements may allow future versions of this specification
to support an extension mechanism based upon the `ext` media type parameter.
> Note: If a client's `Accept` header indicates that it accepts standard JSON
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should encourage this. I believe that this minor wheel greasing will actually be a disservice to clients. If they are required to provide the media type they accept, I suspect they will be more likely to find out what it is before consuming the data from a json-api service blindly.

Copy link
Member

Choose a reason for hiding this comment

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

For context, I intend to provide a formatter for text/html in Endpoints that will return the response in a browser friendly format (tables, hyperlinks, etc).

@tkellen
Copy link
Member

tkellen commented May 27, 2015

👍 from me, without commit a6a051c

dgeb pushed a commit that referenced this pull request May 27, 2015
…nces of violating them

See rationale in #673. Also consolidates all the rules into the content
negotiation section.
@dgeb dgeb mentioned this pull request May 27, 2015
@tkellen
Copy link
Member

tkellen commented May 27, 2015

Closing in favor of #703. Thanks for your work here @ethanresnick!

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.

4 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