Skip to content
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

Add version support in response header #25

Closed
wants to merge 7 commits into from
Closed

Add version support in response header #25

wants to merge 7 commits into from

Conversation

richardnuno
Copy link

Added the ability to specify a response header key in the configuration. When defined, a header field with that key and a value of "true" or "false" (depending on whether the requested version is supported or not) will be set on the response.

Expose is_older_version and is_newer_version booleans to allow someone to customize their error handling depending on whether the requested version is deprecated or newer than any of the supported versions.

…l when the requested version is not supported.

The is_newer_version boolean should be set to true when a requested version is newer than any of the currently supported versions and the is_older_version should be set to true when a requested version is deprecated.
…pending on the requested and supported versions.

Moved the raising of the ActionController::RoutingErrors to the controller_additions.rb.
…he exposed variables and the header value on the response are still set.
…ed version is supported or not.

The header will only be set if the user provides a value for the response_header_key configuration variable.
@coveralls
Copy link

Coverage Status

Coverage increased (+0.1%) when pulling d7df8b4 on bonobos:feature/response-header-version-support into 643c543 on bwillis:master.

@bwillis
Copy link
Owner

bwillis commented Feb 28, 2014

@richardnuno thanks for the pull request. Can you expand on your use case for this feature? Thanks!

@richardnuno
Copy link
Author

Sure thing. The use case is the consumer of the api being able to determine whether the requested version is supported or not when making an ajax request without relying on the http status code and matching of the error message strings. The is_older_version and is_newer_version variables were added as a way to customize the error handling on the consumer depending on whether the version is deprecated or larger than the most recent supported version. Please let me know if you have any suggestions/thoughts on the feature, happy to make the necessary changes.

@aantix
Copy link
Collaborator

aantix commented Feb 28, 2014

@richardnuno Could you add a code example to the Readme that outlines this use case? It's probably easier to evaluate it that way.

…tion variables.

Also added an example of how to read the response header with a JavaScript consumer.
@richardnuno
Copy link
Author

@aantix I've updated the README to contain information about the new variables and an example of how a JavaScript consumer would use the header value to determine if an unsupported version was requested. Let me know if you have any concerns or suggestions on how to improve it.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.1%) when pulling 2f5c4c8 on bonobos:feature/response-header-version-support into 643c543 on bwillis:master.

@bwillis
Copy link
Owner

bwillis commented Mar 1, 2014

@richardnuno Thanks for the clarification of your problem. It seems that this is very close to another recent issue #24.

I think that returning a header field during unsupported version request is a little too specific for Version Cake to handle specifically. That being said, I have taken your PR as a base and attempted to make a more general solution to allow applications to handle unsupported requests in their own way. I would appreciate if you review my PR #26-your feedback would be greatly appreciated.

@richardnuno
Copy link
Author

@bwillis I understand, I'll close this PR and take a look at PR #26. Thanks!

@richardnuno richardnuno closed this Mar 3, 2014
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.

None yet

4 participants