As @Pablo mentioned in the comments, just use .json
in the call to your controller.
As in the following:
GET http://localhost:3000/categories.json
It is expected that your controller will handle both, as is the case in generated controllers.
A specific example: [approot]/app/controllers/category_controller.js
In JavaScript:
action(function index() {
this.title = 'Categories index';
Category.all(function (err, categories) {
respondTo(function (format) {
// Use format.json and the send method to return JSON data when
// .json is specified at the end of the controller
format.json(function () {
send({code: 200, data: categories});
});
format.html(function () {
render({
categories: categories
});
});
});
});
});
In CoffeeScript:
action index = ->
@title = "Categories index"
Category.all (err, categories) ->
respondTo (format) ->
# Use format.json and the send method to return JSON data when
# .json is specified at the end of the controller
format.json ->
send
code: 200
data: categories
format.html ->
render categories: categories