I would like to know if i do something wrong or if it's normal that i can't access the properties of my model on the server side (using express) by calling req.body.username (for example) after a fetch() call:
app.get("/test", function(req, res){
console.log(req.body.username); //Undefined
});
But i can access it the same way by a PUT request.
Actually i used the url to send the username but i would like to clean my routes and access the properties throught req.body instead, (of course after setting it in my model on the client side).
Thanks for the explanation !
UPDATE:
In case it could matter, here is my app configuration:
app.configure(function(){
app.use(express.bodyParser());
app.use(express.cookieParser());
app.use(express.session({secret: 'test', store: express.session.MemoryStore({
reapInterval: 60000 * 10
})}));
});
I'm guessing you use backbone.js on the client, as you've tagged your question with it. Backbone's sync-method by default doesn't seem to attach the model data to the request. You could pass it in as an option to fetch/sync, but it seems JQuery would append the data to the url anyway. You'd probably have to override backbone's sync- and/or ajax-method. I believe it is against REST-principals to include a body in a GET-request though, as indicated in this other answer (a resource has to be completely identified by the URI).