Once you have a request mapped to an action, you can define the logic in the actions.js file.

var actions = module.exports = {

index: function () {

this.render('./views/index.html');

},

foobarAdd: function () {

var req = this.request,

res = this.response;

if (req === 'POST') {

// Do something POSTY; like create a record in the db.

// Then respond back to client.

res.writeHead(200);

res.end()

} else {

this.statusCode(405)

}

}

};

Notice that in the 'foobarAdd' function. The request and response objects are made available through 'this'. This allows flexibility and provides each action access to node's request and response objects.

There are a few functions made available in each action that can assist with handling the logic:

this.postData - Data from a post form.

this.json(obj) - Takes an object and responds to the request with JSON.