{"name":"express-annotations","version":"0.0.2","description":"Module to augment Express routes with metadata","author":{"name":"Eric Ferraiuolo","email":"eferraiuolo@gmail.com"},"homepage":"https://github.com/yahoo/express-annotations","contributors":[{"name":"alberto chan","email":"imalberto@gmail.com"},{"name":"Caridy Patino","email":"caridy@gmail.com"}],"main":"index.js","keywords":["express","modown","routes"],"peerDependencies":{"express":"3.x"},"devDependencies":{"chai":"1.5.x","express":"3.x","istanbul":"*","jshint":"*","mocha":"1.8.x","xunit-file":"*"},"repository":{"type":"git","url":"git://github.com/yahoo/express-annotations.git"},"bugs":{"url":"https://github.com/yahoo/express-annotations/issues"},"engines":{"node":">=0.8.x","npm":">=1.2.10"},"scripts":{"test":"istanbul cover -- node_modules/.bin/_mocha tests/unit/*.js --reporter spec","unit":"mocha tests/unit/*.js --reporter spec","lint":"jshint {.,tests/unit}/*.js","pretest":"jshint {.,tests/unit}/*.js"},"license":"BSD","_id":"express-annotations@0.0.2","dist":{"shasum":"96da0435ad2a6261781a3d254a77f9a817b4c5d8","tarball":"http://registry-npm.ywwl.com/express-annotations/download/express-annotations-0.0.2.tgz","integrity":"sha512-HXOo9SfA0IyOF71g/UcKzVPzg9F86NI4hOXZQNDEp45xEfoik2Bdbt0sLc0Lj8iqC4w7DF3O53BYScLHF8akkw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC6R0IkzyV+eZqj/lgG8jzKZWWA+XvB5wPGbg8PpyNgZgIgLrndRCqbIBO6uHcg2L2FCI2GzCTtTkHh4RAWD2xgi4A="}],"size":2987,"noattachment":false,"key":"/express-annotations/-/express-annotations-0.0.2.tgz"},"_from":".","_npmVersion":"1.3.11","_npmUser":{"name":"ericf","email":"eferraiuolo@gmail.com"},"maintainers":[{"name":"ericf","email":"eferraiuolo@gmail.com"},{"name":"caridy","email":"caridy@gmail.com"},{"name":"imalberto","email":"imalberto@gmail.com"},{"name":"clarle","email":"cleung0@gmail.com"}],"deprecated":"No compatible with ExpressJS 4.x Router","readme":"Express Annotations\n===================\n\n[![Build Status](https://travis-ci.org/yahoo/express-annotations.png?branch=master)](https://travis-ci.org/yahoo/express-annotations)\n[![Dependency Status](https://gemnasium.com/yahoo/express-annotations.png)](https://gemnasium.com/yahoo/express-annotations)\n[![npm Version](https://badge.fury.io/js/express-annotations.png)](https://npmjs.org/package/express-annotations)\n\nAugment your Express routes with metadata, so they can be serialized and shared\nbetween different environments, such as the browser and server.\n\nOverview\n--------\n\n### Goals\n\nWhen creating routes for an application, there's often extra information that \nmight be helpful to be attached to them when rendering them out in a template. \n\nFor instance, if you were creating a navigation menu, and wanted it to be\nupdated automatically whenever you created a new route on your application, it\nmight be useful to know what label you would want the route to have on the menu,\nand what subsection of your application that route would fall under, so you\ncould automatically render it as soon as you set up the route.\n\nExpress Annotations solves this problem for you by giving you the ability to\nset arbitrary metadata on any route in your Express application, which you\nserialize to use in any environment, be in browser or server.\n\n### How It Works\n\nYou specify a route path and an annotations object using \n`app.annotate(path, annotations)`. These annotations are added to an\napp-level annotations object, which you can use to look up the annotations of\nany route in your application.\n\nInstallation\n------------\n\nInstall using npm:\n\n```\n$ npm install express-annotations\n```\n\nUsage\n-----\n\n### Extending an Express App\n\nTo use Express Annotations with an Express app, the app must first be extended.\nUse the `extend()` method that Express Annotations exports:\n\n```js\nvar express     = require('express'),\n    annotations = require('express-annotations'),\n\n    app = express();\n\nannotations.extend(app);\n```\n\nOnce extended, the `app` object will contain two new methods, and a\nnew property, `annotations`:\n\n## Methods\n\n### `app.annotate(path, annotations)`\n\nThis function takes in a given URL path string for a route, and an\nannotations object, which can contain any arbitrary values.\n\nIt maps together that `path` to the provided `annotations` object\ninside of `app.annotations`. If that path has existing annotations in\n`app.annotations`, then the new `annotations` object will extend\nthose existing annotations, overwriting any previous annotations\nwith the same key.\n\nAn example of using this method:\n\n```js\napp.annotate('/movies', {label: 'Movies', section: 'entertainment'});\napp.annotate('/finance', {label: 'Finance', section: 'news'});\n\napp.get('/movies', function (req, res) {\n    // ...\n});\n\napp.get('/finance', function (req, res) {\n    // ...\n});\n```\n\nA common technique to use is to create a sugar method that combines the actual\n`app.VERB()` route with `app.annotate()`, though we kept this separate for more\nflexibility in how you use Express Annotations. The above is functionally\nequivalent to:\n\n```js\nfunction labelPage(path, annotations, callback) {\n    app.annotate(path, annotations);\n    app.get(path, callback);\n}\n\nlabelPage('/movies', {label: 'Movies', section: 'entertainment'}, function (req, res) {\n    // ...\n});\n\nlabelPage('/finance', {label: 'Finance', section: 'news'}, function (req, res) {\n    // ...\n});\n```\n\nThis sets up the annotations for you, which you can use directly by referencing\nthem inside of the `app.annotations` object, or filter them, using the\n`app.findAll` function.\n\n### `app.findAll(annotations)`\n\nThis function returns an object representing the list of available routes,\nsorted by their respective HTTP methods. If no `annotations` are passed in,\nthen all routes are returned (effectively the same as `app.routes`).\n\nAn example object, using the routes above, looks like this:\n\n```js\n{\n    get: [{\n        path: '/movies',\n        method: 'get',\n        callbacks: [Object],\n        keys: [],\n        regexp: /^\\/movies\\/?$/i\n    }, {\n        path: '/finance',\n        method: 'get',\n        callbacks: [Object],\n        keys: [],\n        regexp: /^\\/finance\\/?$/i\n    }]\n}\n```\n\nLike the `app.routes` object, there can be multiple keys (for HTTP methods such\nas `get`, `post`, `put`, `delete`, etc.), and they can also have references to\ntheir parameter keys as well as multiple callbacks.\n\nIf you wanted to get only the routes that were in the `news` section, for\ninstance:\n\n```js\nvar newsRoutes = app.findAll({ section: 'news' });\n/*\nWould only return one route => {\n    get: [{\n        path: '/finance',\n        method: 'get',\n        callbacks: [Object],\n        keys: [],\n        regexp: /^\\/finance\\/?$/i\n    }]\n}\n*/\n```\n\n`app.findAll` is extremely flexible and can take any of the following parameters:\n* Strings (for the key of the annotation)\n* Objects (for a specific key/value pair of the annotation)\n* Arrays (combining a mix of any number of string or object filters)\n* Functions (with anything returning truthy to be considered a match)\n\n## Properties\n\n### `app.annotations`\n\nThis is the annotations object, which simply is just a map between the route\npaths and their annotations. Using the above annotations, we have the following\nobject:\n\n```js\n{\n    '/movies': {\n        label: 'Movies',\n        section: 'entertainment'\n    },\n    '/finance': {\n        label: 'Finance',\n        section: 'news'\n    }\n}\n```\n\nAdvanced Use Cases\n------------------\n\nThere are many possible uses for Express Annotations, particularly with sharing\ndata between client-side routes and server-side routes for single page\napplications.\n\nIt's generally recommended to use [Express Map](https://github.com/yahoo/express-map) as well when using Express Annotations.  You can take a look at some of the\nmore advanced examples with Express Map to see what more complicated\napplications can be created in combination with Express Annotations.\n\nLicense\n-------\n\nThis software is free to use under the Yahoo! Inc. BSD license.\nSee the [LICENSE file][] for license text and copyright information.\n\n[LICENSE file]: https://github.com/yahoo/express-annotations/blob/master/LICENSE.md\n\nContribute\n----------\n\nSee the [CONTRIBUTING file][] for information on contributing back to Express\nMap.\n\n[CONTRIBUTING file]: https://github.com/yahoo/express-annotations/blob/master/CONTRIBUTING.md\n","publish_time":1383631261090,"_cnpm_publish_time":1383631261090,"dist-tags":{"latest":"0.1.0"}}