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

Allow custom formatters to be set with API settings. #277

Merged
merged 1 commit into from
Nov 20, 2012

Conversation

tim-vandecasteele
Copy link
Contributor

Due to their close relationship with content-types, it seems obvious to allow custom formatters to be set in the same way.

Reading the code, and how it is structured, it seems strange this setting is not already available. If this is already available in another way, I completely missed it and this pull request can be closed immediately (I'll submit another pull request to update the documentation so the existing functionality is explicitly mentioned).

@dblock
Copy link
Member

dblock commented Nov 19, 2012

You totally got it. Can you please update CHANGELOG, too?

I think what we want eventually is to treat all these formats the same - refactoring the current formatter and extension madness into something where we start with a bunch of dynamically configured defaults. This could kill code like formatter_for. One of the feature requests is to be able to fail when trying to serve JSON, for example (an XML-only API).

Due to their close relationship with content-types, it seems obvious to allow custom formatters to be set in the same way.
@tim-vandecasteele
Copy link
Contributor Author

While it might not be the most beautiful, for now the feature you describe above could easily be accomplished with my code by overruling the json formatter:

formatter :json, lambda { |object| throw :error, :status => 406, :message => 'The requested format is not supported.' }

@dblock
Copy link
Member

dblock commented Nov 20, 2012

Thank you, merging.

The example works, but don't let it stop you from spending a few days and nights on making Grape even more awesome :)

dblock added a commit that referenced this pull request Nov 20, 2012
Allow custom formatters to be set with API settings.
@dblock dblock merged commit ba0901c into ruby-grape:master Nov 20, 2012
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.

2 participants