I have an api which return huge data, so I want to compress this data and return to the client.
I know there are ways of doing in Nginx
or Rack::deflater in application.rb
. But i want to compress this data only for this particular api response.(don't want to do it in ngnix)
I tried as mentioned in this answer: https://stackoverflow.com/a/35758106/5925134. I am able to compress but not able to respond to client with compressed data. I tried this and want to somehow respond_to gz as response-type.
Zlib::GzipWriter.open('public/huge_data.gz') { |gz| gz.write data.to_json }
respond_to do |format|
format.gz { render gz: {File.read('public/huge_data.gz') } }
end
Is there any way to pass this compressed data to client or any other approach? Thanks in advance