json-rest-api 0.1.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +392 -130
- package/TODO.todo +113 -0
- package/api.js +628 -0
- package/docs/API.md +1306 -0
- package/docs/FIXES_APPLIED.md +59 -0
- package/docs/GUIDES.md +1792 -0
- package/docs/RESOURCES_IN_EXPRESS.md +456 -0
- package/docs/example-versioning.js +168 -0
- package/docs/example.js +195 -0
- package/index.js +58 -207
- package/package.json +15 -25
- package/plugins/API guide.md +364 -0
- package/plugins/api-registry.js +142 -0
- package/plugins/api-versioning.md +135 -0
- package/plugins/http.js +273 -0
- package/plugins/logging.js +255 -0
- package/plugins/memory.js +182 -0
- package/plugins/mysql.js +753 -0
- package/plugins/openapi.js +401 -0
- package/plugins/positioning.js +220 -0
- package/plugins/security.js +261 -0
- package/plugins/validation.js +173 -0
- package/plugins/versioning.js +288 -0
- package/resource-helper.js +79 -0
- package/schema.js +481 -0
- package/test-basic.js +107 -0
- package/.jshintrc +0 -48
- package/.npmignore +0 -15
- package/LICENSE +0 -20
- package/examples/client.js +0 -18
- package/examples/client2.js +0 -27
- package/examples/server.js +0 -23
- package/test.js +0 -101
package/examples/client2.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
var request = require('request');
|
|
3
|
-
var inspect = require('util').inspect;
|
|
4
|
-
var debug = require('debug')('json-rest-api:example:client');
|
|
5
|
-
var assert = require('assert');
|
|
6
|
-
|
|
7
|
-
var data = {
|
|
8
|
-
field1: 'Edmond',
|
|
9
|
-
field2: 100,
|
|
10
|
-
field3: {
|
|
11
|
-
alpha: true,
|
|
12
|
-
beta: [ 0, 1, 2 ],
|
|
13
|
-
gamma: 999
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
request({method:'POST', json:data, uri: 'http://localhost:8000/postData'}, function(err, res, json) {
|
|
18
|
-
if (err) {
|
|
19
|
-
debug('Error: '+inspect(err));
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
debug('typeof json: '+typeof json);
|
|
23
|
-
debug('json: '+inspect(json));
|
|
24
|
-
assert.ok(json.success === true);
|
|
25
|
-
assert.ok(json.pong === 'pong');
|
|
26
|
-
console.log('Success!');
|
|
27
|
-
});
|
package/examples/server.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
var JsonRestApi = require('../index');
|
|
3
|
-
var inspect = require('util').inspect;
|
|
4
|
-
var debug = require('debug')('json-rest-api:example:server');
|
|
5
|
-
|
|
6
|
-
var RestApi = new JsonRestApi({port: 8000}, function(err) {
|
|
7
|
-
if (err) {
|
|
8
|
-
debug('/ping error: '+inspect(err));
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
console.log('Listening on port 8000.');
|
|
12
|
-
|
|
13
|
-
// add a route
|
|
14
|
-
RestApi.addRoute('get', '/ping', function(req, res) {
|
|
15
|
-
res.json({success: true, pong: 'pong'});
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
RestApi.addRoute('post', '/postData', function(req, res, json) {
|
|
19
|
-
console.log(req.body);
|
|
20
|
-
console.log(json);
|
|
21
|
-
res.json({success: true, pong: 'pong'});
|
|
22
|
-
});
|
|
23
|
-
});
|
package/test.js
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
var JsonRestApi = require('./index');
|
|
3
|
-
var request = require('request');
|
|
4
|
-
var inspect = require('util').inspect;
|
|
5
|
-
var debug = require('debug')('json-rest-api:test');
|
|
6
|
-
var assert = require('assert');
|
|
7
|
-
|
|
8
|
-
describe('Test1', function() {
|
|
9
|
-
var RestApi;
|
|
10
|
-
before(function(cb) {
|
|
11
|
-
RestApi = new JsonRestApi({port: 8000}, function(err) {
|
|
12
|
-
debug('IN CB');
|
|
13
|
-
if (err) {
|
|
14
|
-
debug('/ping error: '+inspect(err));
|
|
15
|
-
return cb(err);
|
|
16
|
-
}
|
|
17
|
-
// add a route
|
|
18
|
-
// A simple health check, common to all derived classes.
|
|
19
|
-
RestApi.addRoute('get', '/ping', function(req, res) {
|
|
20
|
-
res.json({success: true, pong: 'pong'});
|
|
21
|
-
});
|
|
22
|
-
cb();
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('should fetch test.html', function(cb) {
|
|
27
|
-
request({json:true, uri: 'http://localhost:8000/ping'}, function(err, res, json) {
|
|
28
|
-
if (err) {
|
|
29
|
-
debug('Error: '+inspect(err));
|
|
30
|
-
return cb(err);
|
|
31
|
-
}
|
|
32
|
-
debug('typeof json: '+typeof json);
|
|
33
|
-
debug('json: '+inspect(json));
|
|
34
|
-
assert.ok(json.success === true);
|
|
35
|
-
assert.ok(json.pong === 'pong');
|
|
36
|
-
cb();
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
after(function(cb){
|
|
41
|
-
RestApi.stop(function(err) {
|
|
42
|
-
if (err) return cb(err);
|
|
43
|
-
debug('RestApi stopped successfully');
|
|
44
|
-
cb();
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
describe('Test2', function() {
|
|
50
|
-
var RestApi;
|
|
51
|
-
before(function(cb) {
|
|
52
|
-
RestApi = new JsonRestApi({port: 8000}, function(err) {
|
|
53
|
-
debug('IN CB');
|
|
54
|
-
if (err) {
|
|
55
|
-
debug('/ping error: '+inspect(err));
|
|
56
|
-
return cb(err);
|
|
57
|
-
}
|
|
58
|
-
// add a route
|
|
59
|
-
// A simple health check, common to all derived classes.
|
|
60
|
-
RestApi.addRoute('get', '/setname', function(req, res, json, qs) {
|
|
61
|
-
debug('qs: '+inspect(qs));
|
|
62
|
-
res.json({success: true, cmd: 'setname', qs: qs});
|
|
63
|
-
});
|
|
64
|
-
cb();
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('should be able receive a query string', function(cb) {
|
|
69
|
-
var qs = {
|
|
70
|
-
alpha: 'one',
|
|
71
|
-
beta: 2,
|
|
72
|
-
gamma: true
|
|
73
|
-
};
|
|
74
|
-
var opts = {
|
|
75
|
-
json: true,
|
|
76
|
-
uri: 'http://localhost:8000/setname',
|
|
77
|
-
qs: qs
|
|
78
|
-
};
|
|
79
|
-
request(opts, function(err, res, json) {
|
|
80
|
-
if (err) {
|
|
81
|
-
debug('Error: '+inspect(err));
|
|
82
|
-
return cb(err);
|
|
83
|
-
}
|
|
84
|
-
debug('typeof json: '+typeof json);
|
|
85
|
-
debug('json: '+inspect(json));
|
|
86
|
-
assert.ok(json.success === true);
|
|
87
|
-
assert.ok(json.cmd === 'setname');
|
|
88
|
-
var qsRet = {'alpha': 'one', 'beta': '2', 'gamma': 'true'};
|
|
89
|
-
assert.deepEqual(qsRet, json.qs);
|
|
90
|
-
cb();
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
after(function(cb){
|
|
95
|
-
RestApi.stop(function(err) {
|
|
96
|
-
if (err) return cb(err);
|
|
97
|
-
debug('RestApi stopped successfully');
|
|
98
|
-
cb();
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
});
|