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 8853793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:44:08+00:00 2026-06-14T13:44:08+00:00

My app is Backbone.js for client-side, Express.js for back-end. I have problems with syncing

  • 0

My app is Backbone.js for client-side, Express.js for back-end.

I have problems with syncing with all parts of my API, using the backbone model and collection(they use urlRoot: “/users”).
I’m allowed to use only GET or POST, no PUT or DELETE.
*I’m not allowed to use more models*
Not allowed to use jQuery ajax

My API

add new user:
I need to make a POST to /users with JSON of new data. So I did it just fine with – this.model.save({new data...})

list all users:
My API for that, responses to GET /users, with the right handler – so, this.collection.fetch() – works fine.

Log-In:
My API accepts POST to /users/login for that. How can I add a function “logIn” to my model, that will use custom sync/pass options.url to sync – or any other way – that will POST to /users/login ?

Log-Out:
API accepts POST to /users/logout – how to send this request using my backbone model ?

User By ID:
Same question here for GET /users/:id

Update user:
POST /users/:id – same question again.

— So actually, the question in short is —

What is the best way (or the most “right”), to implement methods of a backbone model, that are similar to “model.save()” – but just POST/GET to a bit different path then urlRoot ?

  • 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-14T13:44:09+00:00Added an answer on June 14, 2026 at 1:44 pm

    You probably have a couple options here. One would be structuring your models in a way that supports the urls you want. For instance, have a User model and a Session model that deal with updating the user and managing the logged in state separately.

    The other thing you should probably do is to use the url method in your models.

    Something like this in your User model. (Note: using urlRoot instead of url here is identical, but this is the correct approach for anything more complicated that is needed in the url)

    url : function() {
      var base = "/users/";
      if(this.isNew()) {
        return base;
      } else {
        return base + this.get("id");
      }
    }
    

    You could extend this same concept to work in your Session model for handling logout vs login based on if the Session is new or not.

    Update:

    If you must use the same model, the best thing would be to totally bypass the Backbone.sync method and write a custom AJAX call with success/error handlers that know how to clean things up.

    login : function() {
      $.post("/users/login", {success: function (response) {
          // Update user as needed
        }, error: function (xhr, response) {
          // Handle errors
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a single-page web app that's using Backbone.js client routing with pushState. In
I have a client side app I'm working in which Im' using jQuery 1.7.x,
I am building a backbone.js app on a Rails 3.1 back-end. I'm using CoffeeScript
I'm using Backbone.js on the client side and express.js on the server, and I'm
I'm using backbone.js to structure my client side app. Backbone.sync is working nicely for
I am building a small app that uses backbone.js on the client side, node.js/socket.io
I'm building an app with backbone/RequireJs on the front end and node/express on the
I have a Backbone app that queries my Express server with a un/pw, authenticates,
I have the following backbone.js client side template: <script id=calleeTemplate type=text/x-jquery-tmpl> <tr style=background-color: ${StatusColour}>
I'm working on a WebApp using backbone.js and socket.io on the client side, and

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.