If you need to batch up lots of related queries, you can just build it into 
your API, or use LoopBack to do it for you

I've been using LoopBack for my REST api:
http://docs.strongloop.com/display/LB/Querying+models#Queryingmodels-RESTsyntax

It might be too late in your app's lifecycle to integrate, but it makes a 
lot of things so much easier...you basically get a query language in your 
REST API for free.

For the example of loading everyone's conversations, you could do something 
like this...

User.find({include: {'conversations': 'posts'}})

Assuming your model relations are set up appropriately, the loopback 
handler will fetch all the users, and for each one, fetch and attach a list 
of all the conversations they are part of...and for each of those, attach a 
list of all posts in that conversation, then it returns a json list of your 
users with all the nested info with a single http call.

Or you might want just the conversations for one user:

User.find({where: {id: SOMEUSERID}, include: {conversations: 'posts'}})

It doesn't reduce the load on your db or anything, just batches up a bunch 
of related queries into a single network transaction.  Pretty cool, I 
think.  Loopback also has a utility to generate an AngularJS service 
implementing all your models as $resources, so you can use the syntax I 
used above.  Otherwise, you have to translate the json-style queries into 
something like:

GET 
/api/users?filter[where][id]=SOMEUSERID&filter[include][conversations]=posts

Of course, this doesn't help when you just want to batch up a bunch of 
random unrelated requests... :-/

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to