Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Allow custom formatters to be set with API settings. #277
Conversation
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
dblock
Nov 19, 2012
Owner
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).
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). |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
tim-vandecasteele
Nov 20, 2012
Contributor
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.' }
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.' } |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
dblock
Nov 20, 2012
Owner
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 :)
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 :) |
tim-vandecasteele commentedNov 19, 2012
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).