loopback/node_modules/resource
Ritchie Martori 7c2e73f53a Initial working store, model, connection, and collection 2013-04-10 10:55:13 -07:00
..
example Update gitignore to allow node_modules 2013-04-09 11:33:29 -07:00
lib Initial working store, model, connection, and collection 2013-04-10 10:55:13 -07:00
test Initial working store, model, connection, and collection 2013-04-10 10:55:13 -07:00
.gitignore Update gitignore to allow node_modules 2013-04-09 11:33:29 -07:00
README.md Update gitignore to allow node_modules 2013-04-09 11:33:29 -07:00
index.js Update gitignore to allow node_modules 2013-04-09 11:33:29 -07:00
package.json Update gitignore to allow node_modules 2013-04-09 11:33:29 -07:00

README.md

asteroid.Resource

About

A Resource inherits from the asteroid module class. It wraps an asteroid application so that it can be used as a sub application initialized by a configuration file.

This example shows the basic usage of a Resource as a sub application. You should never have to write this code since the resource will be created and mounted for you by asteroid.

var asteroid = require('asteroid');
var Resource = require('resource');

var app = asteroid();
var subApp = new Resource({root: '/my-sub-app'});
subApp.mount(app);

subApp.get('/', function (req, res) {
  res.send(req.url); // /my-sub-app
});

app.listen(3000);

resource.app

Each resource is constructed with a asteroid/express sub app at the path provided in the resource's config.json options.

myResource.app.VERB(path, [callback...], callback)

The myResource.VERB() methods provide routing functionality inherited from Express, where VERB is one of the HTTP verbs, such as myResource.post(). See the Express docs for more info.

Examples

myResource.get('/hello-world', function(req, res) {
  res.send('hello world');
});

myResource.app.use([path], middleware)

Use the given middleware function.

Examples

// a logger middleware
myResource.use(function(req, res, next){
  console.log(req.method, req.url); // GET /my-resource
  next();
});

Config

Options

path

The asteroid.Route path where the resource will be mounted.

Examples

{
  "options": {
    "path": "/foo" // responds at /foo
  }
}
{
  "options": {
    "path": "/foo/:bar" // provides :bar param at `req.param('bar')`.
  }
}