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

Build Formatter Middleware #1

Closed
mbleigh opened this issue Aug 3, 2010 · 0 comments
Closed

Build Formatter Middleware #1

mbleigh opened this issue Aug 3, 2010 · 0 comments

Comments

@mbleigh
Copy link
Contributor

mbleigh commented Aug 3, 2010

The Formatter takes care of handling the various formats into which Grape API responses can be converted. It consists of two parts:

1. Determining from the request what kind of format is desired.

This would first look at any format appended as an extension (i.e. .json or .xml). If no format is appended, it would properly parse and use the HTTP Accept header (including weighted quality values) to determine an array of acceptable formats.

2. Converting data to the desired format.

The middleware would be transparent in Grape, but also usable outside of it. Any data set in the Rack env hash on the key api.response_data should automatically be converted to the desired format (falling back to a to_format call if existing methods aren't in place) and sent along as the response body. A proper content type should also be set based on the used response format.

This should be flexible enough to allow for stranger formats (for example, a PDF or a Zip file response).

dwmcnelis pushed a commit to dwmcnelis/grape that referenced this issue Feb 4, 2013
ramarnat added a commit to ramarnat/grape that referenced this issue Mar 13, 2014
borsothy pushed a commit to borsothy/grape that referenced this issue Aug 1, 2017
This issue was closed.
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

No branches or pull requests

1 participant