I have an API with many urls like:
/users/profile -> GET the currently connected user /users/bestfriend -> GET the currently connected users' best friend (most bestfriend of bestfriends) /users/wife -> GET the currently connected users' wife /users/friends -> GET the currently connected users' friends /users/bestfriends -> GET the currently connected users' best friends /users/childrens -> GET the currently connected users' childrens /users/neighbours -> GET the currently connected users' neighbours
I’m new to Backbone and i don’t really know if the currently connected user should be fetched as a collection or a simple model for exemple.
I know the current user could be boostrapped like the Backbone doc mention but it’s not the point here, just assume i can’t boostrap the current user model.
So how can i redirect my fetches to the API URLs?
Should i provide each time an option like {"operation":"profile"} or {"operation":"friends"}, or modify the collection url before doing the fetch?
Thanks
You have to create several Models and Collections any of them related to one of your URLS.
You also can use
Friendas the parent class ofBestFriend:Or even create a
Personclass as parent for every person:As you have separate URLS to retrieve the data of everyone of the elements you should make several fetches:
You can reference all the elements into your
Profileinstance with things like this:There are several approaches to organize the elements, also to listen to events on them, but all this is just a matter of taste, and which architecture you fill more comfortable with.