I have a api written in rails which on each request response with a JSON response.,
the response is sometime huge, so i need to compress the JSON response using gzip.
How do i do this in rails controller..??
I have added the line
render :json => response.to_json()
For the response to be in gzip format we don't have to change the
render method call.
If the request has the header
Accept-Encoding: gzip, Rails will automatically compress the JSON response using gzip.
If you don't want the user to send a request with preset header., you can add the header to the request manually in the controller before rendering the response:
request.env['HTTP_ACCEPT_ENCODING'] = 'gzip' render :json => response.to_json()