-
-
Notifications
You must be signed in to change notification settings - Fork 33
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
Support for media type version request #14
Comments
Hi! We are actually actively working on this problem :) This module depends on the |
That looks just the thing. We could ideally provide the following as type params: [{
mediaType: 'application/vnd.linn.space-configuration+json',
version: 1
}, {
mediaType: 'application/vnd.linn.sapce-configuration+json',
version: 2
}, {
mediaType: 'json'
}] |
As in, input to this library? If that is that you're suggesting, we already do offer that: typeis(req, ['application/vnd.linn.space-configuration+json; version=1', 'application/vnd.linn.sapce-configuration+json; version=2', 'json']) |
Hi @bazwilliams , sorry this went stale, but it looks like I was waiting for clarification to my question. Can you clarify? |
Yes, using type-is to match the entire string including version does work, but doesn't provide much additional benefit over comparing the header directly. |
Ok, but you still haven't cleared up to me what you want me to do. Can you elaborate more on what you mean in #14 (comment) ? |
Sorry I wasn't clear. If you run the following code: var is=require('type-is');
var req = {
headers: {
'content-type': 'application/vnd.linn.test+json; version=1',
'transfer-encoding': 'chunked'
}
};
//Should be false
console.log(is(req,['application/json']));
//Should be application/vnd.linn.test+json
console.log(is(req,['+json']));
//Should be application/vnd.linn.test+json
console.log(is(req,['application/vnd.linn.test+json']));
//Should be application/vnd.linn.test+json, but also want access to the version which matched!
console.log(is(req,['application/vnd.linn.test+json; version=1', 'application/vnd.linn.test+json; version=2'])); The first 3 examples give output that I would expect. But the last fails to match. Further, it would be useful to be able to find out which version was requested, but particularly important in the last example where our code can receive both version 1 and 2 requests. But unless we parse the header manually, cannot tell what the version of the content-type is. |
Gotcha, makes sense now. So yes, this library doesn't let you match on the parameters. The only way you can do it currently is to include the var contentType = require('content-type')
var typeis = require('type-is')
// ... later on
if (typeis(req, 'application/vnd.linn.test+json')) {
console.log('accepts application/vnd.linn.test+json with version ' + contentType.parse(req).parameters.version)
} PRs to add things like this are always welcome, though, if the above is not an acceptable solution for you. |
Cheers for the workaround, I'd definitely prefer the library to do this so will fork tomorrow for a future PR. |
We use vendor specific media types for all our resources and use versions to differentiate between breaking changes to that resource.
For example:
is our current media type for
application/vnd.linn.space-configuration+json
and type-is correctly returns the type when+json
is used. However, the versioning is lost and we have no way to differentiate between a version 2 of this resource when it becomes available.The text was updated successfully, but these errors were encountered: