Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails disable JSON parsing of POST/PUT/PATCH body

I want to take a large JSON PUT request and process it entirely in the background with Sidekiq. As such, I do not want to automatically parse the incoming JSON from the request's body.

Whats the best practice for accomplishing this on a controller/action-based level?

like image 492
mikeycgto Avatar asked Dec 23 '15 04:12

mikeycgto


1 Answers

As far as I know this is done via Rack middleware, so I don't think you can just disable it for one controller/action right out of the box. You can patch ActionDispatch::ParamsParser similar to what this guy did:

http://www.jkfill.com/2015/02/21/skip-automatic-params-parsing/

You, of course, can write your own middleware that parses the parameters, or specify a custom parser for JSON MIME type.

At last, you can disable the JSON parsing all together. In your config/application.rb add:

 config.middleware.swap ActionDispatch::ParamsParser, ActionDispatch::ParamsParser, Mime::JSON => nil
like image 155
Yevgeniy Goyfman Avatar answered Oct 08 '22 00:10

Yevgeniy Goyfman