connect-rest
Advanced tools
Comparing version 0.9.14 to 1.0.0
@@ -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 ) ); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
220417
22
0
722
8
11
1066
2
+ Addedparseurl@latest
+ Addedcall-bind@1.0.7(transitive)
+ Addedconnect@3.7.0(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addedencodeurl@1.0.2(transitive)
+ Addedes-define-property@1.0.0(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedfinalhandler@1.1.2(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.2.4(transitive)
+ Addedgopd@1.1.0(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-proto@1.1.0(transitive)
+ Addedhas-symbols@1.1.0(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedobject-inspect@1.13.3(transitive)
+ Addedqs@6.13.1(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedside-channel@1.0.6(transitive)
+ Addedutils-merge@1.0.1(transitive)
- Removedaccepts@1.2.131.3.8(transitive)
- Removedbase64-url@1.2.1(transitive)
- Removedbasic-auth@1.0.4(transitive)
- Removedbasic-auth-connect@1.0.0(transitive)
- Removedbatch@0.5.3(transitive)
- Removedbody-parser@1.13.3(transitive)
- Removedbytes@2.1.02.4.0(transitive)
- Removedcompressible@2.0.18(transitive)
- Removedcompression@1.5.2(transitive)
- Removedconnect@2.30.2(transitive)
- Removedconnect-timeout@1.6.2(transitive)
- Removedcontent-type@1.0.5(transitive)
- Removedcookie@0.1.3(transitive)
- Removedcookie-parser@1.3.5(transitive)
- Removedcookie-signature@1.0.6(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removedcrc@3.3.0(transitive)
- Removedcsrf@3.0.6(transitive)
- Removedcsurf@1.8.3(transitive)
- Removeddebug@2.2.0(transitive)
- Removeddepd@1.0.11.1.22.0.0(transitive)
- Removeddestroy@1.0.4(transitive)
- Removederrorhandler@1.4.3(transitive)
- Removedescape-html@1.0.2(transitive)
- Removedetag@1.7.0(transitive)
- Removedexpress-session@1.11.3(transitive)
- Removedfinalhandler@0.4.0(transitive)
- Removedfresh@0.3.0(transitive)
- Removedhttp-errors@1.3.1(transitive)
- Removediconv-lite@0.4.110.4.13(transitive)
- Removedisarray@0.0.1(transitive)
- Removedmedia-typer@0.3.0(transitive)
- Removedmethod-override@2.3.10(transitive)
- Removedmethods@1.1.2(transitive)
- Removedmime@1.3.4(transitive)
- Removedmime-db@1.52.01.53.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedmorgan@1.6.1(transitive)
- Removedms@0.7.10.7.2(transitive)
- Removedmultiparty@3.3.2(transitive)
- Removednegotiator@0.5.30.6.3(transitive)
- Removedon-headers@1.0.2(transitive)
- Removedpause@0.1.0(transitive)
- Removedqs@0.6.64.0.0(transitive)
- Removedrandom-bytes@1.0.0(transitive)
- Removedrange-parser@1.0.3(transitive)
- Removedraw-body@2.1.7(transitive)
- Removedreadable-stream@1.1.14(transitive)
- Removedresponse-time@2.3.3(transitive)
- Removedrndm@1.2.0(transitive)
- Removedsend@0.13.2(transitive)
- Removedserve-favicon@2.3.2(transitive)
- Removedserve-index@1.7.3(transitive)
- Removedserve-static@1.10.3(transitive)
- Removedstatuses@1.2.1(transitive)
- Removedstream-counter@0.2.0(transitive)
- Removedstring_decoder@0.10.31(transitive)
- Removedtsscmp@1.0.5(transitive)
- Removedtype-is@1.6.18(transitive)
- Removeduid-safe@2.0.02.1.4(transitive)
- Removedutils-merge@1.0.0(transitive)
- Removedvary@1.0.11.1.2(transitive)
- Removedvhost@3.0.2(transitive)
Updatedconnect@~3
Updatedqs@latest