Hi eO_Ae,

Thanks for the reply.

I tried the link you gave me and did some research about that 
Backbone.sync, but unable to make it work. 

*Here's my server code:*

// database
var databaseUrl = "mydb";
var collections = ["users", "reports"];
var db = require("mongojs").connect(databaseUrl, collections);

// restify
var restify = require('restify');

var server = restify.createServer({
  name: 'myapp',
  version: '1.0.0'
});
server.use(restify.acceptParser(server.acceptable));
server.use(restify.queryParser());
server.use(restify.bodyParser());

function send(req, res, next) {
userEmail = req.params.email;
userPassword = req.params.password;
db.users.find({email: userEmail}, function(err, users) {
if( err || !users) {
console.log("User not found!");
} else {
console.log(JSON.stringify(userEmail, null, 2));
users.forEach( function(data) {
if (!data) {
res.send("no data");
return next;
} else {
if (userEmail == data.email && userPassword == data.password) {
res.send({ 
"login": {
"email": "[email protected]"
}
});
return next();
} else {
res.send("Login Failed for "+ userEmail + " " + userPassword);
return next();
}
}
});
}
});
}

server.get('/test/api/v1/login.json', send);

server.listen(8080, function () {
console.log('%s listening at %s', server.name, server.url);
});

*and here's my Backbone client code: *

$(function(){
// var MyModel = Backbone.Model.extend();
var MyModel = Backbone.Model.extend({
email: "[email protected]",
password: "1234567"
});
 var methodMap = {
    'create': 'POST',
    'update': 'PUT',
    'delete': 'DELETE',
    'read':   'GET'
};
 var MyCollection = Backbone.Collection.extend({
    url: 'http://localhost:8080/test/api/v1/login.json',
    model: MyModel
});
method = 'read';
Backbone.sync = function(method, MyModel, options){};

});

On Thursday, August 16, 2012 3:48:09 AM UTC+8, eO_Ae wrote:
>
> I think what you're looking for is described in the sync documentation for 
> backbone. http://backbonejs.org/#Sync
>
> On Monday, August 13, 2012 10:54:26 PM UTC-7, almarjin wrote:
>>
>> Hi,
>>
>> I'd like to know how to connect to Nodejs API on the server using 
>> Backbone. What I need to do is to POST, PUT, DELETE and GET.
>>
>> Thanks,
>>
>

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to