Show:
Module: parch

Manages routing

Constructor

Router
(
  • registry
)

Defined in src/router.js:27

Parameters:

Methods

_buildRoute () Object
private

Defined in src/router.js:184

Consistently builds a route from a set of path segments using Route

Returns:

Object:

route object with path property

_generateControllerHandlers
(
  • controller
  • action
)
Array
private

Defined in src/router.js:196

generates main route handler plus pre and post hooks

Parameters:

Returns:

Array:

handlers

_getPathSegment
(
  • resource
  • action
)
String
private

Defined in src/router.js:220

Generates a path segment from a given resource name

Parameters:

Returns:

String:

pathSegment (e.g. :userId)

_loadControllers ()
private

Defined in src/router.js:239

loads controllers from the loader

_lookupSerializer
(
  • name
)
Object
private

Defined in src/router.js:286

Attempts to lookup a serializer by 'name' in the module loader. If one exists it is instantiated and registered by 'name'. If one does not exist the default JSONSerializer is instantiated and registered.

Parameters:

  • name String

    lowercase singular lookup name (e.g. "user")

Returns:

Object:

serializer instance

_mapControllerAction
(
  • resource
  • controller
  • action
  • options
)
private

Defined in src/router.js:316

maps a resource controller action and route

Parameters:

  • resource String

    the resource name

  • controller Object

    the resource controller

  • action String

    the controller method

  • options Object

    mapping options

_registerControllerHooks
(
  • controller
  • handlers
)
private

Defined in src/router.js:345

Registers controller beforeModel and afterModel hooks

Parameters:

_registerLegacyControllerHooks
(
  • controller
  • action
  • handlers
)
private

Defined in src/router.js:363

Registers legacy controller before/after hooks

Parameters:

  • controller Object
  • action String

    controller action type (index, create, update, etc)

  • handlers Array

    restify request handlers

namespace
(
  • namespace
  • routes
)

Defined in src/router.js:61

Available since 0.9.0

Bind a set of routes to a namespace. Uses _buildRoute to normalize the path

Parameters:

  • namespace String

    the namespace to bind to, with or without leading slash

  • routes Object[][]

    array of routes to bind to the namespace

Example:

Router.map(function () {
  this.namespace("/users/:userId", [
    { path: "/setProfileImage", using: "user:setImage", method: "post" }
  ])
});
resource
(
  • name
  • options
)

Defined in src/router.js:95

Register a resource and wire up restful endpoints. Uses _buildRoute to normalize the path and builds your 5 basic CRUD endpoints

Parameters:

  • name String

    the resource name in singular form

  • options Object

    resource mapping options

    • namespace String

      mount the resource endpoint under a namespace

Example:

Router.map(function () {
  this.resource("user");

  // Optionally prefix this resource with a namespace
  this.resource("user", { namespace: "api" })
});
route
(
  • path
  • options
)

Defined in src/router.js:145

Register a single route. Uses _buildRoute to normalize the path

Parameters:

  • path String

    the route path (e.g. /foo/bar)

  • options Object
    • using String

      colon delimited controller method identifier

    • method String

      http method

Example:

Router.map(function () {
  this.route("/user/foo", { using: "users:foo", method: "get" });
});

Properties

loader

Object

Defined in src/router.js:40

Contains the model and controller loaders

namespacePrefix

String

Defined in src/router.js:51

An optional namespace to place before all routes (e.g. /v1)