connect-rest
Advanced tools
Comparing version
@@ -62,2 +62,13 @@ /* | ||
function removePath(key, path, version){ | ||
if( !mapping[ key ] ) return; | ||
var newRoutes = []; | ||
_.each( mapping[ key ], function(route){ | ||
if( !route.matches( null, path, version || '*', _, semver, false, false ) ) | ||
newRoutes.push( route ); | ||
}); | ||
mapping[ key ] = newRoutes; | ||
} | ||
function addPath(key, path, action, prototypeObject, options){ | ||
@@ -197,2 +208,36 @@ options = options || {}; | ||
exports.unhead = function(path, version){ | ||
removePath( "HEAD", path, version ); | ||
}; | ||
exports.unget = function(path, version){ | ||
removePath( "GET", path, version ); | ||
}; | ||
exports.unpost = function(path, version){ | ||
removePath( "POST", path, version ); | ||
}; | ||
exports.unput = function(path, version){ | ||
removePath( "PUT", path, version ); | ||
}; | ||
exports.unpatch = function(path, version){ | ||
removePath( "PATCH", path, version ); | ||
}; | ||
exports.undel = function(path, version){ | ||
removePath( "DELETE", path, version ); | ||
}; | ||
exports.unassign = function headRest(methods, path, version){ | ||
if( _.isString(methods) && methods === '*' ){ | ||
exports.unassign( ['head','get','post','put','patch','delete'], path, version ); | ||
} else if( _.isArray(methods) ){ | ||
_.each( methods, function(element, index, list){ | ||
var method = element.toLowerCase(); | ||
method = (method === 'delete') ? 'del' : method; | ||
if( !exports[ 'un'+ method ] ) | ||
throw new Error('Not known rest type', element); | ||
exports[ 'un'+ method ](path, version); | ||
} ); | ||
} | ||
else | ||
throw new Error('Not correct given methods', methods); | ||
}; | ||
exports.head = function headRest(path, functionRef, options){ | ||
@@ -222,16 +267,6 @@ addPath("HEAD", path, functionRef, null, options ); | ||
var method = element.toLowerCase(); | ||
if( method === 'head' ) | ||
addPath("HEAD", path, functionRef, null, options ); | ||
else if( method === 'get' ) | ||
addPath("GET", path, functionRef, null, options ); | ||
else if( method === 'post' ) | ||
addPath("POST", path, functionRef, prototypeObject, options ); | ||
else if( method === 'put' ) | ||
addPath("PUT", path, functionRef, prototypeObject, options ); | ||
else if( method === 'patch' ) | ||
addPath("PATCH", path, functionRef, prototypeObject, options ); | ||
else if( method === 'delete' ) | ||
addPath("DELETE", path, functionRef, prototypeObject, options ); | ||
else | ||
throw new Error('Not known rest type:', element); | ||
method = (method === 'delete') ? 'del' : method; | ||
if( !exports[ method ] ) | ||
throw new Error('Not known rest type', element); | ||
exports[ method ](path, functionRef, prototypeObject, options); | ||
} ); | ||
@@ -238,0 +273,0 @@ } |
@@ -112,3 +112,3 @@ var PARAMETER_M_DELIMETER = ':'; | ||
return false; | ||
if( this.protector && !this.protector( req, rPathname, version ) ) | ||
if( req && this.protector && !this.protector( req, rPathname, version ) ) | ||
return false; | ||
@@ -123,3 +123,3 @@ | ||
if( alterEnvironment ) | ||
if( req && alterEnvironment ) | ||
_.each(parameterReplacements, function(value, key, list){ | ||
@@ -138,3 +138,3 @@ req.query[ key ] = value; | ||
if( alterEnvironment ) | ||
if( req && alterEnvironment ) | ||
_.each(parameterReplacements, function(value, key, list){ | ||
@@ -141,0 +141,0 @@ req.query[ key ] = value; |
{ | ||
"name": "connect-rest", | ||
"version": "1.4.7", | ||
"version": "1.5.0", | ||
"description": "Exceptionally featureful RESTful web services middleware for Connect.", | ||
@@ -57,3 +57,3 @@ "keywords": [ | ||
}, | ||
"_id": "connect-rest@1.4.7" | ||
"_id": "connect-rest@1.5.0" | ||
} |
@@ -55,2 +55,3 @@ CONNECT-REST - Exceptionally featureful Restful web services middleware for connect node.js | ||
- [Prototype services](#prototype-services) | ||
- [Remove services](#remove-services) | ||
- [Logging](#logging) | ||
@@ -545,2 +546,23 @@ - [Reflective publishing](#reflective-publishing) | ||
## Remove services | ||
One can remove a published service by calling the following function: | ||
rest.unpost( '/shake' ); | ||
That code removes all REST services which would be fired by calling with the URI _'/shake'_. | ||
The same path matching logic is used to determine if a given REST function should be removed. | ||
Every publishing method available in [connect-rest](https://github.com/imrefazekas/connect-rest) has a removing-pair function: | ||
unpost, undel, unget ... unassign | ||
There is a second parameter if you want to specify the version of the services you would like to remove: | ||
rest.unpost( '/shake', 1.0.0 ); | ||
... unlinking the service answering to the given URI with the given version. | ||
[Back to Feature list](#features) | ||
## Logging | ||
@@ -762,2 +784,3 @@ In the option object passed to the constructor, there is an optional parameter 'logger', which enables the logging functionality: | ||
- 1.5.0: remove rest function | ||
- 1.4.0: logging rewritten | ||
@@ -764,0 +787,0 @@ - 1.3.0: range-based mapping added |
1187056
237.33%25
4.17%1334
2.46%831
2.85%