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.0.12 to 0.0.13

28

lib/connect-rest.js

@@ -6,3 +6,3 @@ /*

*/
var VERSION = '0.0.12';
var VERSION = '0.0.13';

@@ -44,4 +44,4 @@ var connect = require('connect');

function addPath(key, path, action, prototypeObject){
mapping[ key ].push( new Route( path, prototypeObject,
function addPath(key, path, action, prototypeObject, validator){
mapping[ key ].push( new Route( path, prototypeObject, validator,
function(request, content, callback){

@@ -115,16 +115,16 @@ callback( null, action(request, content) );

exports.head = function headRest(path, functionRef){
addPath("HEAD", path, functionRef);
exports.head = function headRest(path, functionRef, validator){
addPath("HEAD", path, functionRef, null, validator);
};
exports.get = function getRest(path, functionRef){
addPath("GET", path, functionRef);
exports.get = function getRest(path, functionRef, validator){
addPath("GET", path, functionRef, null, validator);
};
exports.post = function postRest(path, functionRef, prototypeObject){
addPath("POST", path, functionRef, prototypeObject);
exports.post = function postRest(path, functionRef, prototypeObject, validator){
addPath("POST", path, functionRef, prototypeObject, validator);
};
exports.put = function putRest(path, functionRef, prototypeObject){
addPath("PUT", path, functionRef, prototypeObject);
exports.put = function putRest(path, functionRef, prototypeObject, validator){
addPath("PUT", path, functionRef, prototypeObject, validator);
};
exports.delete = function deleteRest(path, functionRef, prototypeObject){
addPath("DELETE", path, functionRef, prototypeObject);
exports.delete = function deleteRest(path, functionRef, prototypeObject, validator){
addPath("DELETE", path, functionRef, prototypeObject, validator);
};

@@ -202,3 +202,3 @@

req, pathname, CONTEXT, req.headers['accept-version'] || req.headers['x-api-version'] || '*', _, semver, true
); }
) && (!route.validator || route.validator(req, res) ); }
);

@@ -205,0 +205,0 @@ var matching = _.map( routes, function(route){ return route.action; } );

var Path = require('./path');
function Route(path, prototypeObject, action, _){
function Route(path, prototypeObject, validator, action, _){
this.action = action;
this.prototypeObject = prototypeObject;
this.validator = validator;
this.paths = [];

@@ -30,4 +31,4 @@

Route.prototype.matchings = function( version, _, semver ){
var found = _.map(
_.filter( this.paths, function( path ){ return path.matchings( version, _, semver); } ), function(path){
var found = _.map(
_.filter( this.paths, function( path ){ return path.matchings( version, _, semver); } ), function(path){
return path.path;

@@ -37,5 +38,5 @@ }

return found;
return found;
};
module.exports = Route;
{
"name": "connect-rest",
"version": "0.0.12",
"version": "0.0.13",
"description": "RESTful web services middleware for Connect.",

@@ -44,4 +44,4 @@ "keywords": [

"readme": "README.md",
"_id": "connect-rest@0.0.12",
"_from": "connect-rest@>=0.0.12"
"_id": "connect-rest@0.0.13",
"_from": "connect-rest@>=0.0.13"
}

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

- [Domain support](#domain-support)
- [Validation](#validation)

@@ -286,2 +287,11 @@ ## Assign

## Validation
When assigning routes with rest API you can pass a validation function as well, which can be used to determine if the REST function can be called in a given circumstances or should be ignored. This could mean authorization or ip address validation or other security concern.
rest.post( [ { path: '/shake', version: '>=2.0.0' }, { path: '/twist', version: '>=2.1.1' } ], function( request, content ){
return JSON.stringify(content);
}, null, function(req, res){ return _.contains(req.user.roles, "superuser"); } );
## Server - extracted from the tests

@@ -347,2 +357,3 @@

- 0.0.13 : Validator function can be also passed
- 0.0.12 : Domain (introduced in Node 0.8.0) support added

@@ -349,0 +360,0 @@ - 0.0.11 : First request parameter now has a callback for async rest calls

@@ -30,4 +30,4 @@ function buildUpRestAPI( rest, _ ){

console.log( 'Received:' + JSON.stringify( request ) + ' ' + JSON.stringify(content) );
throw new Error('Shake error...');
//return JSON.stringify(content);
//throw new Error('Shake error...');
return JSON.stringify(content);
}, {'title': 'Alice in Wonderland'} );

@@ -34,0 +34,0 @@ }

@@ -60,11 +60,11 @@ var rest = require('../lib/connect-rest');

async.parallel([
//async.apply( caller.testCall1, http, _ ),
//async.apply( caller.testCall2, http, _ ),
//async.apply( caller.testCall3a, http, _ ),
//async.apply( caller.testCall3b, http, _ ),
//async.apply( caller.testCall4, http, _ ),
//async.apply( caller.testCall5, http, _ ),
async.apply( caller.testCall6, http, _ )
//async.apply( caller.testCall7, http, _ ),
//async.apply( caller.testCall8, http, _ )
async.apply( caller.testCall1, http, _ ),
async.apply( caller.testCall2, http, _ ),
async.apply( caller.testCall3a, http, _ ),
async.apply( caller.testCall3b, http, _ ),
async.apply( caller.testCall4, http, _ ),
async.apply( caller.testCall5, http, _ ),
async.apply( caller.testCall6, http, _ ),
async.apply( caller.testCall7, http, _ ),
async.apply( caller.testCall8, http, _ )
], function(err, results){

@@ -71,0 +71,0 @@ console.log('Tests finished.');

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