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.14 to 1.0.0

mochaTest.log

11

lib/connect-rest.js

@@ -9,2 +9,4 @@ /*

var connect = require('connect');
var qs = require('qs');
var parseurl = require('parseurl');
var url = require('url');

@@ -261,3 +263,6 @@ var async = require('async');

return function(req, res, next) {
return function restMaker(req, res, next) {
if (!req.query)
req.query = req.url.indexOf('?') ? qs.parse( parseurl(req).query ) : {};
if( domain ){

@@ -280,4 +285,2 @@ domain.add(req);

if(!req.query) req.query = {};
logger.info('Incoming request.', req.headers, req.query, req.httpVersion, req.method, req.originalUrl );

@@ -302,3 +305,3 @@

if( matching.length === 0 ){
if( API_KEYS && API_KEYS.indexOf(req.query.api_key) === -1 ){
if( API_KEYS && API_KEYS.indexOf( apiKey ) === -1 ){
logger.info('Request without api key.', req.query );

@@ -305,0 +308,0 @@

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

@@ -33,15 +33,22 @@ "keywords": [

"async": "latest",
"winston": "latest",
"connect": "~2",
"connect": "~3",
"lodash": "latest",
"parseurl": "latest",
"qs": "latest",
"semver": "~2",
"underscore.string": "latest",
"qs": "~0.6",
"semver": "~2"
"winston": "latest"
},
"devDependencies": {
"body-parser": "latest",
"chai": "latest",
"compression": "latest",
"connect-timeout": "latest",
"cookie-parser": "latest",
"cookie-session": "latest",
"gulp": "latest",
"gulp-jshint": "latest",
"gulp-load-plugins": "latest",
"gulp-mocha": "latest"
"gulp-mocha": "latest",
"serve-static": "latest"
},

@@ -51,3 +58,3 @@ "engines": {

},
"_id": "connect-rest@0.9.14"
"_id": "connect-rest@1.0.0"
}

@@ -5,2 +5,6 @@ CONNECT-REST - Exceptionally featureful Restful web services middleware for connect node.js

__Important__ : [connect-rest](https://github.com/imrefazekas/connect-rest) __>v1.0__ is compatible with [connect](http://www.senchalabs.org/connect/) __>v3.0__. All examples/tests are complying with this rule!
For [connect](http://www.senchalabs.org/connect/) __v2__, please use the version __0.9.14__ of [connect-rest](https://github.com/imrefazekas/connect-rest)!
========

@@ -22,4 +26,5 @@ [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.

__!Note__: connect-rest's concept is - as for integration - to provide a connect plugin and to be a framework for your rest services carrying only about content and business logic, nothing else. However, in case of need for interoperability, the need might cause you to use only the path-related features alone. This can be done using [dispatchers](#dispatchers).
__!Note__: connect-rest's concept is to provide a feature-full connect middleware for your rest services carrying only about content and business logic, nothing else. However, in case of need for interoperability, the need might cause you to use only the path-related features alone. This can be done using [dispatchers](#dispatchers).
# Usage

@@ -64,3 +69,5 @@

// requires connect and connect-rest middleware
var connect = require('connect');
var connect = require('connect'),
bodyParser = require('body-parser');
var rest = require('connect-rest');

@@ -71,6 +78,4 @@

var connectApp = connect();
.use( connect.query() )
.use( connect.session( { ... } ) )
.use( connect.urlencoded() )
.use( connect.json() )
.use( bodyParser.urlencoded( { extended: true } ) )
.use( bodyParser.json() )
;

@@ -81,7 +86,7 @@

var options = {
apiKeys: [ '849b7648-14b8-4154-9ef2-8d1dc4c2b7e9' ], // to set up api-key restriction
discoverPath: 'discover', // activates discovery service
protoPath: 'proto', // activates prototype service
logger:{ name: 'your appname', level: 'info' }, // activates logger
context: '/api' // general context used for URIs of connect-rest
context: '/api',
logger:{ file: 'mochaTest.log', level: 'debug' },
apiKeys: [ '849b7648-14b8-4154-9ef2-8d1dc4c2b7e9' ],
discoverPath: 'discover',
protoPath: 'proto'
};

@@ -679,3 +684,4 @@

- 0.9.1: fixes...
- 1.0.0: Switch to connect v3!
- 0.9.x: fixes...
- 0.9.0: context specification at REST function level is allowed.

@@ -682,0 +688,0 @@ - 0.8.x: fixes...

var should = require("chai").should();
var http = require('http');
var connect = require('connect');
var http = require('http');
var bodyParser = require('body-parser');
var rest = require('../lib/connect-rest');

@@ -20,9 +22,10 @@ var restBuilder = require('./restBuilder');

before(function(done){
var app = connect().use( connect.query() )
.use( connect.urlencoded() )
.use( connect.json() );
var app = connect()
.use( bodyParser.urlencoded( { extended: true } ) )
.use( bodyParser.json() )
;
var options = {
context: '/api',
logger:{ file: 'test.log', level: 'debug' },
logger:{ file: 'mochaTest.log', level: 'debug' },
apiKeys: [ '849b7648-14b8-4154-9ef2-8d1dc4c2b7e9' ],

@@ -46,6 +49,7 @@ discoverPath: 'discover',

});
// function(serverURL, method, headers, err, result, mimetype, logger, callback){
describe("rest", function () {
describe("rest", function () {
it('HEAD call is', function(done){
httphelper.generalCall( 'http://localhost:8080/api/peek?api_key=849b7648-14b8-4154-9ef2-8d1dc4c2b7e9', 'HEAD', null, null, null, 'application/json', logger,
httphelper.generalCall( 'http://localhost:8080/api/peek', 'HEAD', {'x-api-key':'849b7648-14b8-4154-9ef2-8d1dc4c2b7e9'}, null, null, 'application/json', logger,
function(err, result, status){

@@ -61,3 +65,3 @@ should.not.exist( err ); should.exist( result );

it('GET for "empty" service call is', function(done){
httphelper.generalCall( 'http://localhost:8080/api/empty?api_key=849b7648-14b8-4154-9ef2-8d1dc4c2b7e9', 'GET', null, null, null, 'application/json', logger,
httphelper.generalCall( 'http://localhost:8080/api/empty', 'GET', {'x-api-key':'849b7648-14b8-4154-9ef2-8d1dc4c2b7e9'}, null, null, 'application/json', logger,
function(err, result, status){

@@ -73,3 +77,3 @@ should.not.exist(err);

it('mandatory parameter mapping is', function(done){
httphelper.generalCall( 'http://localhost:8080/api/books/AliceInWonderland/1?api_key=849b7648-14b8-4154-9ef2-8d1dc4c2b7e9', 'GET', null, null, null, 'application/json', logger,
httphelper.generalCall( 'http://localhost:8080/api/books/AliceInWonderland/1', 'GET', {'x-api-key':'849b7648-14b8-4154-9ef2-8d1dc4c2b7e9'}, null, null, 'application/json', logger,
function(err, result, status){

@@ -88,3 +92,3 @@ should.not.exist(err);

it('optional parameter mapping v1 is', function(done){
httphelper.generalCall( 'http://localhost:8080/api/store?api_key=849b7648-14b8-4154-9ef2-8d1dc4c2b7e9', 'POST', null, null, {'message': 'ok'}, 'application/json', logger,
httphelper.generalCall( 'http://localhost:8080/api/store', 'POST', {'x-api-key':'849b7648-14b8-4154-9ef2-8d1dc4c2b7e9'}, null, {'message': 'ok'}, 'application/json', logger,
function(err, result, status){

@@ -102,3 +106,3 @@ should.not.exist(err);

it('optional parameter mapping v2 is', function(done){
httphelper.generalCall( 'http://localhost:8080/api/store/108?api_key=849b7648-14b8-4154-9ef2-8d1dc4c2b7e9', 'POST', null, null, {'message': 'ok'}, 'application/json', logger,
httphelper.generalCall( 'http://localhost:8080/api/store/108', 'POST', {'x-api-key':'849b7648-14b8-4154-9ef2-8d1dc4c2b7e9'}, null, {'message': 'ok'}, 'application/json', logger,
function(err, result, status){

@@ -116,3 +120,3 @@ should.not.exist(err);

it('versioning is', function(done){
httphelper.generalCall( 'http://localhost:8080/api/make?api_key=849b7648-14b8-4154-9ef2-8d1dc4c2b7e9', 'POST', {'accept-version':'1.1.0'}, null, {'message': 'ok'}, 'application/json', logger,
httphelper.generalCall( 'http://localhost:8080/api/make', 'POST', {'accept-version':'1.1.0'}, null, {'message': 'ok'}, 'application/json', logger,
function(err, result, status){

@@ -128,3 +132,3 @@ should.not.exist(err);

it('missing parameter mapping v1 is', function(done){
httphelper.generalCall( 'http://localhost:8080/api/set?api_key=849b7648-14b8-4154-9ef2-8d1dc4c2b7e9', 'GET', null, null, null, 'application/json', logger,
httphelper.generalCall( 'http://localhost:8080/api/set', 'GET', {'x-api-key':'849b7648-14b8-4154-9ef2-8d1dc4c2b7e9'}, null, null, 'application/json', logger,
function(err, result, status){

@@ -139,3 +143,3 @@ should.not.exist(err); should.exist(result);

it('missing parameter mapping v2 is', function(done){
httphelper.generalCall( 'http://localhost:8080/api/set/abraka/dabra?api_key=849b7648-14b8-4154-9ef2-8d1dc4c2b7e9', 'GET', null, null, null, 'application/json', logger,
httphelper.generalCall( 'http://localhost:8080/api/set/abraka/dabra', 'GET', {'x-api-key':'849b7648-14b8-4154-9ef2-8d1dc4c2b7e9'}, null, null, 'application/json', logger,
function(err, result, status){

@@ -153,3 +157,3 @@ should.not.exist(err); should.exist(result);

it('array-typed parameter mapping is ', function(done){
httphelper.generalCall( 'http://localhost:8080/api/data/items?ids%5B%5D=8&ids%5B%5D=9&api_key=849b7648-14b8-4154-9ef2-8d1dc4c2b7e9', 'GET', null, null, null, 'application/json', logger,
httphelper.generalCall( 'http://localhost:8080/api/data/items?ids%5B%5D=8&ids%5B%5D=9', 'GET', {'x-api-key':'849b7648-14b8-4154-9ef2-8d1dc4c2b7e9'}, null, null, 'application/json', logger,
function(err, result, status){

@@ -159,2 +163,3 @@ should.not.exist(err); should.exist(result);

console.log( '>>>>>>>>', result );
result.ids.should.eql( ['8','9'] );

@@ -168,3 +173,3 @@

it('complete parameter mapping is', function(done){
httphelper.generalCall( 'http://localhost:8080/api/call/Skynet/Shira/1.0/request?api_key=849b7648-14b8-4154-9ef2-8d1dc4c2b7e9', 'GET', null, null, null, 'application/json', logger,
httphelper.generalCall( 'http://localhost:8080/api/call/Skynet/Shira/1.0/request', 'GET', {'x-api-key':'849b7648-14b8-4154-9ef2-8d1dc4c2b7e9'}, null, null, 'application/json', logger,
function(err, result, status){

@@ -186,3 +191,3 @@ should.not.exist(err); should.exist(result);

it('versionless paremeter mapping is', function(done){
httphelper.generalCall( 'http://localhost:8080/api/call/Skynet/Shira/request?api_key=849b7648-14b8-4154-9ef2-8d1dc4c2b7e9', 'GET', null, null, null, 'application/json', logger,
httphelper.generalCall( 'http://localhost:8080/api/call/Skynet/Shira/request', 'GET', {'x-api-key':'849b7648-14b8-4154-9ef2-8d1dc4c2b7e9'}, null, null, 'application/json', logger,
function(err, result, status){

@@ -202,3 +207,3 @@ should.not.exist(err); should.exist(result);

it('lazy calling is', function(done){
httphelper.generalCall( 'http://localhost:8080/api/call/Skynet/request?api_key=849b7648-14b8-4154-9ef2-8d1dc4c2b7e9', 'GET', null, null, null, 'application/json', logger,
httphelper.generalCall( 'http://localhost:8080/api/call/Skynet/request', 'GET', {'x-api-key':'849b7648-14b8-4154-9ef2-8d1dc4c2b7e9'}, null, null, 'application/json', logger,
function(err, result, status){

@@ -218,3 +223,3 @@ should.not.exist(err); should.exist(result);

it('embedded parameter mapping is', function(done){
httphelper.generalCall( 'http://localhost:8080/api/eset/abraka/dabra?api_key=849b7648-14b8-4154-9ef2-8d1dc4c2b7e9', 'GET', null, null, null, 'application/json', logger,
httphelper.generalCall( 'http://localhost:8080/api/eset/abraka/dabra', 'GET', {'x-api-key':'849b7648-14b8-4154-9ef2-8d1dc4c2b7e9'}, null, null, 'application/json', logger,
function(err, result, status){

@@ -232,3 +237,3 @@ should.not.exist(err); should.exist(result);

it('unprotected zone calling is', function(done){
httphelper.generalCall( 'http://localhost:8080/api/unprotected', 'GET', null, null, null, 'application/json', logger,
httphelper.generalCall( 'http://localhost:8080/api/unprotected', 'GET', {'x-api-key':'849b7648-14b8-4154-9ef2-8d1dc4c2b7e9'}, null, null, 'application/json', logger,
function(err, result, status){

@@ -246,3 +251,3 @@ should.not.exist(err); should.exist(result);

it('dispatcher is', function(done){
httphelper.generalCall( 'http://localhost:8080/dispatcher/call?api_key=849b7648-14b8-4154-9ef2-8d1dc4c2b7e9', 'GET', null, null, null, 'application/json', logger,
httphelper.generalCall( 'http://localhost:8080/dispatcher/call', 'GET', {'x-api-key':'849b7648-14b8-4154-9ef2-8d1dc4c2b7e9'}, null, null, 'application/json', logger,
function(err, result, status){

@@ -256,3 +261,3 @@ should.equal(result, 'Dispatch call made:call');

it('unprotected dynamic binding call is ', function(done){
httphelper.generalCall( 'http://localhost:8080/pages/workspace', 'GET', null, null, null, 'application/json', logger,
httphelper.generalCall( 'http://localhost:8080/pages/workspace', 'GET', {'x-api-key':'849b7648-14b8-4154-9ef2-8d1dc4c2b7e9'}, null, null, 'application/json', logger,
function(err, result, status){

@@ -268,2 +273,3 @@ should.not.exist(err); should.exist(result);

});
});

@@ -270,0 +276,0 @@

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

});
rest.get('/empty', function( request ){

@@ -79,3 +80,3 @@ console.log( 'Received:' + request.format() );

return rest.dispatcher( 'GET', '/dispatcher/:subject', function(req, res, next){
res.end( 'Dispatch call made:' + req.params['subject'] );
res.end( 'Dispatch call made:' + req.params.subject );
} );

@@ -82,0 +83,0 @@ }

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

});
rest.get('/empty', function( request ){ var delay = Math.round( Math.random() * 100 + 50 );

@@ -10,0 +11,0 @@ console.log( 'Received:' + JSON.stringify( request ) );

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