New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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.3 to 0.0.4

16

lib/connect-rest.js

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

*/
var VERSION = '0.0.3';
var VERSION = '0.0.4';

@@ -31,2 +31,4 @@ var util = require('util');

var API_KEYS;
function addPath(key, path, action){

@@ -81,7 +83,14 @@ mapping[ key ].push( new Route( path,

addPath('GET', options.discoverPath + '/:version', discover );
API_KEYS = options.apiKeys;
}
return function(req, res, next) {
this.options = options || { };
if(!req.query) req.query = {};
if( API_KEYS && API_KEYS.indexOf(req.query.api_key)==-1 ){
res.statusCode = 401;
res.end( 'API_KEY is required.' );
return;
}
var matching = _.map( _.filter(

@@ -98,5 +107,2 @@ mapping[ req.method ], function(route){ return route.matches(

if(!req.query)
req.query = {};
var body = '';

@@ -103,0 +109,0 @@ req.on('data', function(chunk) {

{
"name": "connect-rest",
"version": "0.0.3",
"version": "0.0.4",
"description": "RESTful web services middleware for Connect.",

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

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

@@ -103,3 +103,18 @@ [connect-rest](https://github.com/imrefazekas/connect-rest) is a small middleware for [connect](http://www.senchalabs.org/connect/) for building REST APIs.

## API_KEY management
The option passed to the connect-rest might contain an array enumerating accepted api_keys:
var options = {
'apiKeys': [ '849b7648-14b8-4154-9ef2-8d1dc4c2b7e9' ],
'discoverPath': 'discover'
};
If property 'apiKeys' is present, the associated array of strings will be used as the list of api keys demanded regarding every incoming calls.
So having such option, a call should look like this:
'/api/books/AliceInWonderland/1?api_key=849b7648-14b8-4154-9ef2-8d1dc4c2b7e9'
otherwise error response will be sent with status code 401 claiming: 'API_KEY is required.'.
## Server - extracted from the tests

@@ -115,7 +130,8 @@

var options = {
'discoverPath': 'discover'
'apiKeys': [ '849b7648-14b8-4154-9ef2-8d1dc4c2b7e9' ],
'discoverPath': 'discover'
};
connectApp.use( rest.rester( options ) );
rest.get('/books/:title', functionN0 );
rest.get('/books/:title/:chapter', functionN0 );

@@ -163,8 +179,9 @@ rest.post( { path: '/make', version: '>=1.0.0' }, functionN1 );

- logging services should be added properly
- api_key management
- optional parameters [chapter]
## Changelog
- 0.0.4 : API_KEY management added
- 0.0.3 : discovery managemenet added
- 0.0.2 : named parameters added
- 0.0.1 : initial release

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

var voptions = _.clone( options );
voptions.path = '/api/peek';
voptions.path = '/api/peek?api_key=849b7648-14b8-4154-9ef2-8d1dc4c2b7e9';
voptions.method = 'HEAD';

@@ -41,3 +41,3 @@

var voptions = _.clone( options );
voptions.path = '/api/books/AliceInWonderland/1';
voptions.path = '/api/books/AliceInWonderland/1?api_key=849b7648-14b8-4154-9ef2-8d1dc4c2b7e9';
voptions.method = 'GET';

@@ -44,0 +44,0 @@

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

var options = {
'apiKeys': [],
'apiKeys': [ '849b7648-14b8-4154-9ef2-8d1dc4c2b7e9' ],
'discoverPath': 'discover'

@@ -21,0 +21,0 @@ };

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