Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

connect-rest

Package Overview
Dependencies
Maintainers
1
Versions
190
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

connect-rest - npm Package Compare versions

Comparing version 0.9.5 to 0.9.6

12

lib/bus.js

@@ -1,3 +0,1 @@

var newrelic = require('./newrelic');
function Bus(httphelper) {

@@ -26,8 +24,2 @@ this.httphelper = httphelper;

this.options = options;
if(options.newrelic){
options.newrelic.version = options.newrelic.version || options.version;
options.newrelic.host = options.newrelic.host || options.host;
this.newrelic = new newrelic( options.newrelic, this.httphelper, logger );
}
}

@@ -59,6 +51,2 @@ };

if(this.options.newrelic){
self.newrelic.populate( self.metrics, self.lastPopulation );
}
if(this.options.listener){

@@ -65,0 +53,0 @@ this.options.listener( self.metrics );

24

lib/connect-rest.js

@@ -15,6 +15,4 @@ /*

var https = require('https');
var _ = require('underscore');
var _ = require('lodash');
_.str = require('underscore.string');
_.mixin(_.str.exports());
_.str.include('Underscore.string', 'string');

@@ -50,3 +48,3 @@ var Route = require('./route');

function addPath(key, path, action, prototypeObject, options){
options = options || {};
options = options || {};
mapping[ key ].push( new Route( bus, CONTEXT, path, prototypeObject, options,

@@ -68,6 +66,6 @@ function(request, content, callback){

function protoPather( request, content ){
var utokens = _.words( request.parameters.path, '/');
var utokens = _.str.words( request.parameters.path, '/' );
var method = _.first( utokens );
var version = utokens[1];
var pathname = '/' + _.toSentence( _.rest(utokens, 2 ), '/', '/' );
var pathname = '/' + _.str.toSentence( _.rest(utokens, 2 ), '/', '/' );

@@ -102,4 +100,4 @@ var routes = _.filter(

var getClientAddress = function (req) {
return (req.headers['x-forwarded-for'] || '').split(',')[0]
|| req.connection.remoteAddress;
return (req.headers['x-forwarded-for'] || '').split(',')[0]
|| req.connection.remoteAddress;
};

@@ -114,7 +112,7 @@ */

req.headers.httpVersion=req.httpVersion; req.headers.method=req.method; req.headers.originalUrl=req.originalUrl;
req.parameters = req.params = req.query;
req.format = function(){
return JSON.stringify( { headers: this.headers, parameters: this.parameters, session: this.session, files: this.files } );
}.bind( req );
return async.apply( func, req, bodyObj );
req.parameters = req.params = req.query;
req.format = function(){
return JSON.stringify( { headers: this.headers, parameters: this.parameters, session: this.session, files: this.files } );
}.bind( req );
return async.apply( func, req, bodyObj );
} );

@@ -121,0 +119,0 @@

var http = require('http');
var https = require('https');
var _ = require('underscore');
var _ = require('lodash');
var url = require('url');

@@ -71,2 +71,2 @@ var querystring = require('querystring');

req.end();
};
};

@@ -40,8 +40,8 @@ var PARAMETER_M_DELIMETER = ':';

var utokens = _.words( pathname, '/');
var ptokens = _.words( path, '/');
var utokens = _.str.words( pathname, '/' );
var ptokens = _.str.words( path, '/' );
if( ptokens.length != utokens.length ){
for (var i=1; i<=ptokens.length; i++)
if( _( ptokens[ ptokens.length-i ] ).startsWith( PARAMETER_O_DELIMETER ) && utokens.length < ptokens.length ){
if( _.str.startsWith( ptokens[ ptokens.length-i ], PARAMETER_O_DELIMETER ) && utokens.length < ptokens.length ){
utokens.splice( utokens.length-i + 1, 0, '' );

@@ -52,8 +52,8 @@ }

for (var i=ptokens.length-1; i>=0; i--)
if( _( ptokens[i] ).startsWith( PARAMETER_O_DELIMETER ) && utokens.length < ptokens.length ){
if( _.str.startsWith( ptokens[i], PARAMETER_O_DELIMETER ) && utokens.length < ptokens.length ){
utokens.splice( i, 0, '' );
}
*/
if( _( _.last( ptokens ) ).startsWith( PARAMETER_G_DELIMETER ) ){
var newUToken = _.toSentence( _.rest(utokens, ptokens.length-1 ), '/', '/' );
if( _.str.startsWith( _.last( ptokens ), PARAMETER_G_DELIMETER ) ){
var newUToken = _.str.toSentence( _.rest(utokens, ptokens.length-1 ), '/', '/' );

@@ -68,7 +68,7 @@ utokens = _.first(utokens, ptokens.length );

for (var t=0; t<utokens.length; t++){
if( _( ptokens[t] ).startsWith( PARAMETER_M_DELIMETER ) )
if( _.str.startsWith( ptokens[t], PARAMETER_M_DELIMETER ) )
parameterReplacements[ ptokens[t].substring( PARAMETER_M_DELIMETER.length ) ] = utokens[t];
else if( _( ptokens[t] ).startsWith( PARAMETER_G_DELIMETER ) )
else if( _.str.startsWith( ptokens[t], PARAMETER_G_DELIMETER ) )
parameterReplacements[ ptokens[t].substring( PARAMETER_G_DELIMETER.length ) ] = utokens[t];
else if( _( ptokens[t] ).startsWith( PARAMETER_O_DELIMETER ) ){
else if( _.str.startsWith( ptokens[t], PARAMETER_O_DELIMETER ) ){
if( utokens[t].length>0 )

@@ -87,3 +87,3 @@ parameterReplacements[ ptokens[t].substring( PARAMETER_O_DELIMETER.length ) ] = utokens[t];

Path.prototype.matches = function( req, pathname, version, _, semver, alterEnvironment, protectAPI ){
if( !( _(pathname).startsWith( this.context ) ) )
if( !( _.str.startsWith( pathname, this.context ) ) )
return false;

@@ -90,0 +90,0 @@ var rPathname = pathname.substring( this.context.length );

{
"name": "connect-rest",
"version": "0.9.5",
"version": "0.9.6",
"description": "Exceptionally featureful RESTful web services middleware for Connect.",

@@ -32,9 +32,9 @@ "keywords": [

"dependencies": {
"async": ">=0.2.9",
"underscore": "~1",
"underscore.string": "~2",
"semver": "~2",
"async": "latest",
"bunyan": ">=0.22.0",
"connect": "~2",
"qs": "~0.6"
"lodash": "latest",
"underscore.string": "latest",
"qs": "~0.6",
"semver": "~2"
},

@@ -51,3 +51,3 @@ "devDependencies": {

},
"_id": "connect-rest@0.9.5"
"_id": "connect-rest@0.9.6"
}

@@ -572,7 +572,2 @@ [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.

listener: function(data){ ... }
, newrelic: {
platformApiUri: 'https://platform-api.newrelic.com/platform/v1/metrics',
licenseKey: 'XXX',
pluginName: 'org.vii.connectrest.performancePlugin'
}
}

@@ -587,7 +582,3 @@ };

The property _newrelic_ - if present - activates the [newrelic](https://newrelic.com) services posting all metrics to the newrelic server. You have to give your license key to make it work properly.
Note: [newrelic](https://newrelic.com) support is preliminary at this moment. Will be improved by time...
## More examples

@@ -594,0 +585,0 @@

@@ -25,3 +25,2 @@ var httphelper = require('../../lib/http-helper');

testEmpty: function(test){

@@ -28,0 +27,0 @@ httphelper.generalCall( 'http://localhost:8080/api/empty?api_key=849b7648-14b8-4154-9ef2-8d1dc4c2b7e9', 'GET', null, null, null, 'application/json', logger,

@@ -73,2 +73,3 @@ function buildUpRestAPI( rest ){

} );
}

@@ -75,0 +76,0 @@

@@ -66,4 +66,5 @@ function buildUpRestAPI( rest ){

}, { contentType:'application/json' } );
}
exports.buildUpRestAPI = buildUpRestAPI;

@@ -59,7 +59,2 @@ var rest = require('../lib/connect-rest');

listener: function(data){ console.log( '%j', data); }
/*, newrelic: {
platformApiUri: 'https://platform-api.newrelic.com/platform/v1/metrics',
licenseKey: 'XXX',
pluginName: 'org.vii.connectrest.performancePlugin'
}*/
}

@@ -82,2 +77,1 @@ };

});

@@ -1,8 +0,8 @@

[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.
[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):
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
- 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

@@ -17,3 +17,3 @@ - "reflective" publishing: by providing a single object, its methods will be published as rest services automatically by simple logic

The [connect-rest](https://github.com/imrefazekas/connect-rest) is a simple, yet powerful middleware for [connect](http://www.senchalabs.org/connect/), inspired by [restify](http://mcavage.github.com/node-restify/).
The [connect-rest](https://github.com/imrefazekas/connect-rest) is a simple, yet powerful middleware for [connect](http://www.senchalabs.org/connect/), inspired by [restify](http://mcavage.github.com/node-restify/).
The aim is to focus on the business logic, so [connect-rest](https://github.com/imrefazekas/connect-rest) is managing body payload and parameters as well in the background, your business logic function does not need to take care of any request or response object at all.

@@ -54,3 +54,3 @@

## Assign
Assign your rest modules by one of the http request functions: head, get, post, put, delete.
Assign your rest modules by one of the http request functions: head, get, post, put, delete.

@@ -67,4 +67,4 @@ Example:

After each assign function you might pass the followings:
- a path descriptor and
After each assign function you might pass the followings:
- a path descriptor and
- a function to be called.

@@ -75,19 +75,19 @@

Simple path:
Simple path:
'/peek'
Versioned path:
Versioned path:
{ path: '/make', version: '>=1.0.0' }
Multiple path:
Multiple path:
[ '/act', '/do' ]
Multiple versioned path:
Multiple versioned path:
[ { path: '/shake', version: '<2.0.0' }, { path: '/twist', version: '>=2.1.1' } ]
Mandatory variables:
Mandatory variables:

@@ -97,3 +97,3 @@ { path: '/make/:uid', version: '>=1.0.0' }

Optional path:
Optional path:

@@ -118,3 +118,3 @@ { path: '/delete/?id', version: '>=1.0.0' }

Every handler function receives
- a 'request' object containing "headers" and "parameters" values and a "callback" function if the result is composed by asnyc operations
- a 'request' object containing "headers" and "parameters" values and a "callback" function if the result is composed by asnyc operations
- an optional 'content' object which is the JSON-parsed object extracted from the http body's payload.

@@ -210,7 +210,7 @@ - an optional callback function. This is the 'node standard' way to manage callbacks if needed.

paths. This results to have the parameter 'book' with value
paths. This results to have the parameter 'book' with value
'alice/in/wonderland' or 'oz/the/great/wizard'
'alice/in/wonderland' or 'oz/the/great/wizard'
respectively.
respectively.

@@ -221,3 +221,3 @@ You can make rather complex mixtures of those options as well:

One can call this with uri:
One can call this with uri:

@@ -247,3 +247,3 @@ 'borrow/2/AliceInWonderland' or 'borrow/2/HG1232131/AliceInWonderland'

## Discovery services
[connect-rest](https://github.com/imrefazekas/connect-rest) provides a built-in service: discover. Via a simple get request, it allows you - by specifying a version - to discover the plublished REST apis matching the given version.
[connect-rest](https://github.com/imrefazekas/connect-rest) provides a built-in service: discover. Via a simple get request, it allows you - by specifying a version - to discover the plublished REST apis matching the given version.

@@ -255,3 +255,3 @@ var options = {

This will enable this service - considering the context descrived above - on the path '/api/discover/:version'. Sending a get request to - lets say - this path
This will enable this service - considering the context descrived above - on the path '/api/discover/:version'. Sending a get request to - lets say - this path

@@ -275,3 +275,3 @@ http://localhost:8080/api/discover/3.0.0

That parameter debriefs the client what structure the functionN expects to receive.
That parameter debriefs the client what structure the functionN expects to receive.
To activate this feature, first you have to add a new attribute to the options object:

@@ -290,4 +290,4 @@

will retrieve the object
will retrieve the object
{'title': 'Alice in Wonderland'}

@@ -337,3 +337,3 @@

You can set:
- a string, which will be interpret as the name of the logger seen in the logs, or
- a string, which will be interpret as the name of the logger seen in the logs, or
- passing a bunyan instance to be used.

@@ -347,3 +347,3 @@

## Reflective publishing
[connect-rest](https://github.com/imrefazekas/connect-rest) allows you to have an extremely easy and fast way to publish your services.
[connect-rest](https://github.com/imrefazekas/connect-rest) allows you to have an extremely easy and fast way to publish your services.

@@ -368,6 +368,6 @@ You can define your own services like this in a file (services.js in this example):

This will discover all functions assigned to the exports having a name which conforms the following regular expression:
/^[a-zA-Z]([a-zA-Z]|\d|_)*$/g
The logic is simple. If the function has
The logic is simple. If the function has
- 1 parameter: it will be a 'get' method

@@ -378,3 +378,3 @@ - 2 parameters: it will be a 'post' method

/health on Get
/health on Get
/record on Post

@@ -398,3 +398,3 @@

logger: 'connect-rest',
domain: restDomain
domain: restDomain
};

@@ -410,3 +410,3 @@

{
{
contentType: ''

@@ -445,7 +445,2 @@ validator: ...

listener: function(data){ ... }
, newrelic: {
platformApiUri: 'https://platform-api.newrelic.com/platform/v1/metrics',
licenseKey: 'XXX',
pluginName: 'org.vii.connectrest.performancePlugin'
}
}

@@ -456,8 +451,6 @@ };

The property _console_ - if present - will print the commulated execution times grouped/structured by paths and version to the console.
The property _console_ - if present - will print the commulated execution times grouped/structured by paths and version to the console.
The property _listener_ - if present - allows you to pass a function which the populated data will be sent to. This way you can define own function to process the collected measurements.
The property _newrelic_ - if present - activates the [newrelic](https://newrelic.com) services posting all metrics to the newrelic server. You have to give your license key to make it work properly.
Note: [newrelic](https://newrelic.com) support is preliminary at this moment. Will be improved by time...

@@ -470,3 +463,3 @@

var rest = require('connect-rest');
var connectApp = connect();

@@ -491,3 +484,3 @@

rest.post( [ '/act', '/do' ], functionN2 );
rest.post( [ { path: '/shake', version: '>=2.0.0' }, { path: '/twist', version: '>=2.1.1' } ], functionN3 );

@@ -537,4 +530,4 @@

- 0.0.23-25: small fix for content type management
- 0.0.22: response header customization added
- 0.0.21:
- 0.0.22: response header customization added
- 0.0.21:
- async rest calling allowed by passing a http parameter: callbackURL

@@ -545,3 +538,3 @@ - and some logging fixes

- 0.0.18: fixes
- 0.0.16:
- 0.0.16:
- better optional parameter handling allowing to use optional parameter chain like: /set/?depoartment/?room

@@ -562,2 +555,2 @@ - rewritten assing services. instead of passing a single validator, one has to pass on optional object: { contentType: '', validator: ...} which allows one to define validator and answer return content mime-type as well.

- 0.0.2 : named parameters added
- 0.0.1 : initial release
- 0.0.1 : initial release
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc