You’re not receiving notifications from this thread.
Is there a "Rails" way to batch process API requests?
I have a situation where I'm generating N post requests for given table in a vuejs app, but sending them to the rails controller one by one. I'd like to batch them all up in the app as a JSON object, then send one request over and let rails parse it out.
Would this be as simple as writing a custom controller action?
Wondering if rails has a framework/method for handling batch requests or if there's some standard approaches I should be using.
You're exactly right. If you send them over as an array, Rails can just loop through the array in the params and create them all one-by-one.
Then you just have to decide how you want to handle errors. Some cases you may want to cancel everything if one fails and return the error as JSON, or return JSON with two arrays of the successful and unsuccessful creates. Depends on what you need really.
Ryan Bates made a Railscast on this way back when I guess. http://railscasts.com/episodes/414-batch-api-requests I might have to do something similar in a future episode. 👍
Very helpful, thanks.