Skip to content

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

2 participants