-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrepresentor.js
53 lines (43 loc) · 1.33 KB
/
representor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*******************************************************
* TPS - Task Processing Service
* representation router (server)
* May 2015
* Mike Amundsen (@mamund)
* Soundtrack : Complete Collection : B.B. King (2008)
*******************************************************/
// handles internal representation routing (based on conneg)
// load representors
//var html = require('./representors/html.js');
var json = require('./representors/json.js');
var haljson = require('./representors/haljson.js');
var wstljson = require('./representors/wstljson.js');
var siren = require('./representors/siren.js');
var defaultFormat = "application/vnd.siren+json";
module.exports = main;
function main(object, mimeType, root) {
var doc;
// clueless? assume JSON
if (!mimeType) {
mimeType = defaultFormat;
}
// dispatch to requested representor
switch (mimeType.toLowerCase()) {
case "application/vnd.wstl+json":
doc = wstljson(object, root);
break;
case "application/json":
doc = json(object, root);
break;
case "application/vnd.hal+json":
doc = haljson(object, root);
break;
case "application/vnd.siren+json":
doc = siren(object, root);
break;
default:
doc = siren(object, root);
break;
}
return doc;
}
// EOF