Code Monkey home page Code Monkey logo

Comments (10)

ethanresnick avatar ethanresnick commented on June 25, 2024

Hi @benno208,

Thanks for reporting this! I just pushed a new version of the library that shouldn't have this problem; can you check?

Here's how it should behave now. First, the server should no longer send, and clients no longer need to indicate that they'll Accept, the supported-ext parameter. This is because extensions have now been marked as experimental and, in fact, the whole extension negotiation system may well change. So, until the extension system is more solid, I've chosen not to support the ext and supported-ext at all.

As for the charset parameter: if a client includes it in the Accept header, JSON API requires that the server respond with a 406 Not Acceptable. The idea is that, by requiring an explicit error, JSON API can add new parameters in the future (like ext) to the base spec, and clients can detect server support for those new parameters by seeing whether they get a 406.

The story with charset in Content-Type is different, though. First, express adds charset automatically, so there's little I can do about that. This is bad behavior on express's part, since JSON API's media type doesn't define a charset parameter, but it's not technically a violation of the media type spec. Nevertheless, if a client encounters charset in Content-Type, it MUST simply ignore it. This comes from JSON API but also from the media type spec, which says that "MIME implementations must ignore any parameters whose names they do not recognize".

So, in the end, here's what this adds up to:

  1. Your test client's Accept header should be simply application/vnd.api+json, since supported-ext is gone and including charset will trigger the JSON-API-mandated 406.
  2. Your client's Content-Type header should simply be application/vnd.api+json as well, as mandated here.
  3. Then, your expect clause should be that the returned Content-Type will be application/vnd.api+json; charset=utf8, even though this doesn't match the Accept header. This is a bit annoying—and it's a consequence of express's insistence on adding the charset parameter automatically, which I'd like to figure out some way to disable. But it's perfectly valid under HTTP, which says that using negotiation is optional ("If...none of the available representations for the response have a media type that is listed as acceptable, the origin server can... disregard the header field by treating the response as if it is not subject to content negotiation"). Moreover, it's consistent with JSON API's restrictions as well.

from json-api.

 avatar commented on June 25, 2024

First thing after updating to 2.3.0:

Cannot find module 'babel-core/polyfill'

from json-api.

ethanresnick avatar ethanresnick commented on June 25, 2024

Weird.... I just did a fresh install and things appear to be running fine. Can you give me the stack trace for that error?

from json-api.

 avatar commented on June 25, 2024

I did a complete install. Now everything seems to be fine. When I do a POST I get

expected "Content-Type" of "application/vnd.api+json; charset=utf-8", got "application/json; charset=utf-8"

and on PATCH:

Error: expected "Content-Type" of "application/vnd.api+json; charset=utf-8", got "application/vnd.api+json"

from json-api.

ethanresnick avatar ethanresnick commented on June 25, 2024

What's the Accept header you're sending? For some reason, it's thinking that generic JSON should be used rather than the JSON API media type.

from json-api.

 avatar commented on June 25, 2024

I'm sending the following headers:

headers =
  'Content-Type' : 'application/vnd.api+json'
  'Accept' : 'application/vnd.api+json'

And I'm testing for:

response_headers =
   'Content-Type' : 'application/vnd.api+json; charset=utf-8'

from json-api.

 avatar commented on June 25, 2024

Damn, I clicked the false button...

from json-api.

ethanresnick avatar ethanresnick commented on June 25, 2024

Very weird...what you posted earlier should have worked (and was working for me). However, I've just pushed a new version of the library that removes the automatically-appended charset parameter all together. So now you should be able to send a request with:

Content-Type: application/vnd.api+json
Accept : application/vnd.api+json

And get back

Content-Type: application/vnd.api+json

There's a test for this behavior and, on my machine at least, it's passing. Let me know if you're still experiencing problems after upgrading to the latest version :)

from json-api.

 avatar commented on June 25, 2024

Now, everything works like expected. Thanks!

from json-api.

ethanresnick avatar ethanresnick commented on June 25, 2024

Awesome!

from json-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.