Comments (10)
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:
- Your test client's
Accept
header should be simplyapplication/vnd.api+json
, sincesupported-ext
is gone and includingcharset
will trigger the JSON-API-mandated 406. - Your client's
Content-Type
header should simply beapplication/vnd.api+json
as well, as mandated here. - Then, your expect clause should be that the returned
Content-Type
will beapplication/vnd.api+json; charset=utf8
, even though this doesn't match theAccept
header. This is a bit annoying—and it's a consequence of express's insistence on adding thecharset
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.
First thing after updating to 2.3.0:
Cannot find module 'babel-core/polyfill'
from json-api.
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.
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.
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.
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.
Damn, I clicked the false button...
from json-api.
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.
Now, everything works like expected. Thanks!
from json-api.
Awesome!
from json-api.
Related Issues (20)
- Filtering not working for me HOT 7
- Patch requests problem HOT 1
- Performance: Fetching a relationship needlessly loads the whole resource HOT 1
- Filtering relationships HOT 1
- Duplicate scheme in root object.
- json-api reads from Raw URLs instead of decoded HOT 3
- Allow feature to populate embedded data HOT 2
- Fastify integration HOT 3
- Incorrect Content-type on responses HOT 5
- Provide Koa example
- Filter not working HOT 8
- andWhere query is not working HOT 11
- Issue with serverless
- Add debug environment variable on README.md HOT 1
- Suggestion for Projects
- Example in README.md has unused variable 'opts' HOT 1
- Express `req.host` deprecation warning HOT 3
- How to work around `id` and `type` field names? HOT 4
- Svelte js Express Firebase?
- Please give a workable example HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json-api.