node-rest-ws
Library for creating powerful self-documenting and testable REST + WebSocket API's.
Example
{ 'use strict'; var Server = Server config = server = config apis = server i; for i = 0; i < apislength; i++ server; serverstart;};
Test API
{ 'use strict'; var Deferred = defer; { } // following are API test requests // TODO create an actual automatic test suite based on these // 200 test-sync/1/2/3 > {"a":2,"b":4,"c":6} // 404 test-sync/1/2/3/4 > {"code":"ResourceNotFound","message":"/test-sync/1/2/3/4 does not exist"} TestApiprototype { return a: a * 10 b: b * 10 c: c * 10 ; }; TestApiprototype { return a: a * 2 b: b * 2 c: c * 2 ; }; // 200 test-async/1/2/3 > {"a":2,"b":4,"c":6} // 404 test-async/1/2/3/4 > {"code":"ResourceNotFound","message":"/test-sync/1/2/3/4 does not exist"} TestApiprototype { var deferred = ; ; return deferredpromise; }; // 500 test-async-fail-message > {"code":"InternalError","message":"request failed (meh)"} TestApiprototype { var deferred = ; ; return deferredpromise; }; // 500 test-async-fail-error > {"code":"InvalidArgument","message":"missing \"foobar\" argument"} TestApiprototype { var deferred = ; ; return deferredpromise; }; // 500 test-async-fail-undefined > {"code":"InternalError","message":"request failed for unknown reason"} TestApiprototype { var deferred = ; ; return deferredpromise; }; // 500 test-sync-undefined > {"code":"InternalError","message":"service returned undefined, this should not happen (perhaps forgot to use deferred for async request?)"} TestApiprototype { // don't return anything }; // 500 test-async-undefined > {"code":"InternalError","message":"service returned undefined, this should not happen (perhaps forgot to use deferred for async request?)"} TestApiprototype { var deferred = ; ; return deferredpromise; }; // 500 test-async-unresolved > TestApiprototype { var deferred = ; // never resolved return deferredpromise; }; // 404 test-null > {"code":"ResourceNotFound","message":"Not found"} TestApiprototype { return null; }; // 404 test-false > {"code":"ResourceNotFound","message":"Not found"} TestApiprototype { return false; }; // 200 test-string > "hello world" TestApiprototype { return 'hello world'; }; // 500 test-error > {"code":"InternalError","message":"request failed: foobar is not defined"} TestApiprototype { ; // jshint ignore:line }; // 500 test-exception > {"code":"InternalError","message":"request faile: Something went wrong"} TestApiprototype { throw 'Something went wrong'; }; // 500 test-async-undefined > {"code":"InternalError","message":"request timed out after 10000ms"} TestApiprototype { var deferred = ; ; return deferredpromise; }; contextexports = TestApi;}module