connect-rest
Advanced tools
Comparing version 0.0.32 to 0.0.40
@@ -6,3 +6,3 @@ /* | ||
*/ | ||
var VERSION = '0.0.32'; | ||
var VERSION = '0.0.40'; | ||
@@ -22,3 +22,5 @@ var connect = require('connect'); | ||
var Route = require('./route'); | ||
var Bus = require('./bus'); | ||
var httphelper = require('./http-helper'); | ||
var bus = new Bus(httphelper, _); | ||
@@ -48,5 +50,4 @@ var LOAD_SIZE_LIMIT = 1e6; | ||
function addPath(key, path, action, prototypeObject, options){ | ||
mapping[ key ].push( new Route( path, prototypeObject, options, | ||
mapping[ key ].push( new Route( bus, path, prototypeObject, options, | ||
function(request, content, callback){ | ||
@@ -226,2 +227,4 @@ if(action.length == 3) { | ||
bus.initBus( options.monitoring, logger ); | ||
logger.info('connect-rest has been configured. ', options); | ||
@@ -269,3 +272,3 @@ } | ||
); | ||
var matching = _.map( routes, function(route){ return route.action; } ); | ||
var matching = _.map( routes, function(route){ return route.maction; } ); | ||
@@ -272,0 +275,0 @@ if( matching.length === 0 ){ |
@@ -21,2 +21,6 @@ var PARAMETER_M_DELIMETER = ':'; | ||
Path.prototype.representation = function(){ | ||
return this.isRegex || this.isString ? { path: this.path, version:'*' } : { path: this.path.path, version: this.path.version||'*' }; | ||
}; | ||
Path.prototype.matches = function( req, pathname, version, _, semver, alterEnvironment ){ | ||
@@ -23,0 +27,0 @@ if( this.isRegex ){ |
var Path = require('./path'); | ||
function Route(path, prototypeObject, options, action, _){ | ||
function Route( bus, path, prototypeObject, options, action, _){ | ||
this.bus = bus; | ||
var self = this; | ||
this.action = action; | ||
this.maction = function(request, content, callback){ | ||
var time = Date.now(); | ||
action( request, content, function(err, response){ | ||
self.bus.reportCall( request.headers.originalUrl, self.routes, (Date.now()-time) ); | ||
callback( err, response ); | ||
} ); | ||
}; | ||
this.prototypeObject = prototypeObject; | ||
@@ -17,2 +28,4 @@ this.options = options || {}; | ||
} | ||
this.routes = _.map( this.paths, function(path){ return path.representation(); } ); | ||
} | ||
@@ -19,0 +32,0 @@ |
{ | ||
"name": "connect-rest", | ||
"version": "0.0.32", | ||
"version": "0.0.40", | ||
"description": "RESTful web services middleware for Connect.", | ||
@@ -49,4 +49,4 @@ "keywords": [ | ||
"readme": "README.md", | ||
"_id": "connect-rest@0.0.32", | ||
"_from": "connect-rest@>=0.0.32" | ||
"_id": "connect-rest@0.0.40", | ||
"_from": "connect-rest@>=0.0.40" | ||
} |
@@ -1,3 +0,15 @@ | ||
[connect-rest](https://github.com/imrefazekas/connect-rest) is a middleware for [connect](http://www.senchalabs.org/connect/) for building REST APIs providing service discovery and path-based parameter mapping and "reflective" publishing and node domains as well. | ||
[connect-rest](https://github.com/imrefazekas/connect-rest) is a featureful very easy-to-use middleware for [connect](http://www.senchalabs.org/connect/) for building REST APIs. The library has a stunning feature list beyond basic rest functionality. | ||
Just a few examples: (far from incomplete): | ||
- execution branches: a single service can have multiple paths and a single incoming request can invoke multiple services | ||
- versioning: rest services can be versioned via many ways | ||
- regular expressions: path description can be given using regular expression | ||
- parameter mappings: path matchings can be bound as parameters | ||
- service discovery: built-in rest service allowing one to discover what rest services are available in general or for a given version | ||
- "reflective" publishing: by providing a single object, its methods will be published as rest services automatically by simple logic | ||
- customizable HTTP management: HTTP status code, mime-types can be set at service and execution level | ||
- async services: a rest service can call back asynchronously when the answer is made | ||
- monitoring/measuring: every rest service execution can be enabled for measurement to be collected and populated internally or for external monitoring solutions | ||
# Usage | ||
@@ -36,2 +48,3 @@ | ||
- [Answering async rest requests](#answering-async-rest-requests) | ||
- [Monitoring](#monitoring) | ||
- [Usage](#usage) | ||
@@ -405,2 +418,19 @@ - [Changelog](#changelog) | ||
## Monitoring | ||
[connect-rest](https://github.com/imrefazekas/connect-rest) allows you to monitor and measure the execution of the published rest services. Every service execution measure the execution time and reports to a bus transparently. The commulated data is populated regularly as configured. | ||
var options = { | ||
..., | ||
monitoring: { | ||
populateInterval: 6000, | ||
console: true | ||
} | ||
}; | ||
By adding a monitoring to the options of the library, the monitoring can be activated. The population interval is defined via the _populateInterval_ property measured in millisecs. The property _console_ - if present - will print the commulated execution times grouped/structured by paths and version to the console. | ||
Note: [newrelic](https://newrelic.com) support is under heavy development ... | ||
## Usage | ||
@@ -468,3 +498,4 @@ | ||
- 0.0.30: minor fixes, refined documentation | ||
- 0.0.40: monitoring services (bus) added | ||
- 0.0.3X: minor fixes, refined documentation | ||
- 0.0.28.29: a case when mandatory parameter follows optional(s) has been fixed | ||
@@ -471,0 +502,0 @@ - 0.0.26-27: async request fix |
@@ -51,3 +51,7 @@ var rest = require('../lib/connect-rest'); | ||
context: '/api', | ||
domain: restDomain | ||
domain: restDomain, | ||
monitoring: { | ||
populateInterval: 6000, | ||
console: true | ||
} | ||
}; | ||
@@ -54,0 +58,0 @@ connectApp.use( rest.rester( options ) ); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
56302
16
798
524