Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8377555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:42:02+00:00 2026-06-09T15:42:02+00:00

I have an API with many urls like: /users/profile -> GET the currently connected

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:42:03+00:00Added an answer on June 9, 2026 at 3:42 pm

    You have to create several Models and Collections any of them related to one of your URLS.

    var Profile = Backbone.Model.extend({
      url: "/users/profile"
    });
    
    var BestFriend = Backbone.Model.extend({
      url: "/users/bestfriend"
    });
    
    // ...
    
    var Friend = Backbone.Model.extend({});
    
    var Friends = Backbone.Collection.extend({
      model: Friend,
      url: "/users/friends"
    });
    

    You also can use Friend as the parent class of BestFriend:

    var BestFriend = Friend.extend({
      url: "/users/bestfriend"
    });
    

    Or even create a Person class as parent for every person:

    var Person = Backbone.Model.extend({});
    
    var Friends = Backbone.Collection.extend({
      model: Person,
      url: "/users/friends"
    });
    
    var Profile = Person.extend({
      url: "/users/profile"
    });
    
    var BestFriend = Person.extend({
      url: "/users/bestfriend"
    });
    

    As you have separate URLS to retrieve the data of everyone of the elements you should make several fetches:

    var profile = new Profile();
    var bestFriend = new BestFriend();
    var friends = new Friends();
    
    profile.fetch();
    bestfriend.fetch();
    friends.fetch();
    

    You can reference all the elements into your Profile instance with things like this:

    var Profile = Person.extend({
      url: "/users/profile",
      initialize: function( opts ){
        this.bestFriend = opt.bestfriend;
        // ...
      }
    });
    
    var bestFriend = new BestFriend();
    var friends = new Friends();
    
    var profile = new Profile({
      bestfriend: bestfriend
    });
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For getting Geographical Position of a user we have so many API's can any
After experimenting with many IMAP API's, I have decided to write my own (Most
I see many Java packages have api, impl and bundle jars (name-api.jar, name-impl.jar, name-bundle.jar).
I'm trying to compile many files using the Compiler API. Say I have a
Here, the Sencha team explains how to have a one to many relationship: http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.Store
I have an API in the form of a JAR that I would like
I have an API call that returns a byte array. I currently stream the
It is just a webview that have many api to native functions? Can I
We have JS API does many things based on the HTML (markup semantics and
Many Win32 API functions have parameters specified to be out. For example, GetIconInfo() description

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.