Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
titleapis/test.js
languagejs
var Arrow = require('arrow');

var TestAPI = Arrow.API.extend({
    group: 'test',
    path: '/api/test/:id',
    method: 'GET',
    description: 'this is an api that shows how to implement an API',
    model: 'user',
    before: 'formatRequestBlock',
    after: ['cachingBlock', 'analyticsBlock'],
    parameters: {
        // 'id' is required to execute this endpoint
        id: {description:'the user id'}
    },
    action: function (req, res, next) {
        // call the 'find' method on our model to get the data passing the incoming path value id
        res.stream(req.model.find, req.params.id, next);
    }
});

module.exports = TestAPI;

...

Code Block
titleweb/routes/testroute.js
languagejs
var TestRoute = Arrow.Router.extend({
    name: 'car',
    path: '/car',
    method: 'GET',
    description: 'get some cars',
    action: function (req, res, next) {

        req.server.getAPI('api/car', 'GET').execute({}, function(err, results) {
            if (err) {
                next(err);
            } else {
                req.log.info('got cars ' + JSON.stringify(results));
                res.render('car', results);
            }
        });
    }
});

module.exports = TestRoute;