# Batch POST/PUT with REST?

**URL:** <https://www.ruby-forum.com/t/batch-post-put-with-rest/131509>\
**Category:** Rails\
**Created:** [March 10, 2008, 8:44pm UTC](https://www.ruby-forum.com/t/batch-post-put-with-rest/131509 "2008-03-10T20:44:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![starmaerker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@starmaerker](https://www.ruby-forum.com/u/starmaerker)\
**Post date:** [March 10, 2008, 8:44pm UTC](https://www.ruby-forum.com/t/batch-post-put-with-rest/131509/1 "2008-03-10T20:44:51Z")

</div>

Is there any facility in RoR to create/edit multiple objects with a  
single call.

I am developing an application which allows users to upload data via a  
REST API. The only issue is that people will be creating 1000’s of  
records at a time. Is there some way using standard REST to make a  
single XML document with all those records, and import them over a  
single HTTP transaction, rather than opening and breaking down 1000’s  
of connections.

Something like:  
  
  
…  
  
  
…

Similarly, is there way to do a batch update where the XML document  
has the id as an attribute of the record?

Thanks,

Andrew

---

<div class="post-metadata">

**Author:** ![starmaerker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@starmaerker](https://www.ruby-forum.com/u/starmaerker)\
**Post date:** [March 10, 2008, 11:19pm UTC](https://www.ruby-forum.com/t/batch-post-put-with-rest/131509/2 "2008-03-10T23:19:12Z")

</div>

On Mon, Mar 10, 2008 at 12:33 PM, Andrew S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Similarly, is there way to do a batch update where the XML document  
> has the id as an attribute of the record?
> 
> Thanks,
> 
> Andrew

REST: yes, Rails’ default REST conventions, no. You’d want to create  
a separate action to handle arrays of XML.

map.resources :records, :collection =\> {:import =\> :post}

POST records/import

params[:records] in the controller action would be the array of xml.  
From there, you can loop through params[:records] and create them.

Now, I don’t know how long creating and validating 1000 records at a  
time would take, but it may be a good idea to make this into a  
separate resource that tracked which records failed or were invalid.

map.resources :records  
map.resources :imports, :path\_prefix =\> ‘records/’

POST records/imports, store the xml as a file somewhere, and give the  
client an ID so they can check the status later. Then use some queue  
(bj, starling, beanstalk) to handle this asynchronously, and let the  
user know if the import has problems, and give them an option to  
resolve them.

–  
Rick O.  
[http://lighthouseapp.com](http://lighthouseapp.com)  
[http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
[http://mephistoblog.com](http://mephistoblog.com)
