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

Merged
merged 1 commit into from Nov 20, 2012

Conversation

Projects
None yet
2 participants
@tim-vandecasteele
Contributor

tim-vandecasteele commented Nov 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).

@dblock

This comment has been minimized.

Show comment Hide comment
@dblock

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).

Owner

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).

Tim Vandecasteele
Allow custom formatters to be set with API settings.
Due to their close relationship with content-types, it seems obvious to allow custom formatters to be set in the same way.
@tim-vandecasteele

This comment has been minimized.

Show comment Hide comment
@tim-vandecasteele

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.' }
Contributor

tim-vandecasteele commented Nov 20, 2012

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

This comment has been minimized.

Show comment Hide comment
@dblock

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 :)

Owner

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

Merge pull request #277 from tim-vandecasteele/formatters_via_settings
Allow custom formatters to be set with API settings.

@dblock dblock merged commit ba0901c into ruby-grape:master Nov 20, 2012

1 check passed

default The Travis build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment