0

i'd like to fetch a bunch of models via a collection by a list of model IDs. My problem is that i have to fetch dozens of models at once. I don't want to put dozens over douzens of IDs into the URL when firing a GET request.

I'm thinking about a POST request. But can this be done via Collection?

Maybe this way: https://gist.github.com/2953670

I know i'm raping a POST/create request. Alternatively i have jQuery.post() in mind.

What is the better way?

Thanks in advance, JW

jaydoubleyou
  • 340
  • 6
  • 19
  • Could you please explain why you need such a functionality? If all those models have something in common, it would be better to mark them with some tag and perform a list request filtering by that tag. – Yaroslav Jun 19 '12 at 13:06
  • I have just a list of model IDs (40-100) on client side. Based on this list i need to fetch the models from the server. Another approach would be to provide all available models on client side, but there are a lot of models available (1000+). – jaydoubleyou Jun 19 '12 at 13:25
  • It looks like pagination: 'GET /collection?sort=id&offset=40&limit=60' – Yaroslav Jun 19 '12 at 15:17
  • No way. The list of IDs on client side is scattered e.g. 3, 13, 14, 64, 121, 229, 391, ... . – jaydoubleyou Jun 19 '12 at 18:21
  • 1
    Unfortunately batch operations don't fit well into rest architecture, I'm afraid you have to invent your own bicycle. A bit of information I found: http://stackoverflow.com/questions/511281/patterns-for-handling-batch-operations-in-rest-web-services – Yaroslav Jun 20 '12 at 10:53

1 Answers1

1

Everytime a model/collection does a sync call, it actually does return (this.sync || Backbone.sync).call.... This allows you to implement a custom sync for a specific model or collection.

var Equipment.Collection = Backbone.Collection.extend({ 
    ...

    "sync": urSync,

    ...
});
Anthony Chua
  • 1,198
  • 13
  • 16