-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepresentor.js
More file actions
50 lines (40 loc) · 1.28 KB
/
representor.js
File metadata and controls
50 lines (40 loc) · 1.28 KB
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
/*******************************************************
* service: bigco customer management
* module: representor router
* Mike Amundsen (@mamund)
*******************************************************/
// handles internal representation routing (based on conneg)
// load representors
var json = require('./representors/json.js');
var html = require('./representors/html.js');
var wstljson = require('./representors/wstljson.js');
var jsonlinks = require('./representors/json-links.js');
var jsonforms = require('./representors/json-forms.js');
var defaultFormat = "application/prs.forms+json";
module.exports = main;
function main(object, mimeType, root) {
var doc;
if (!mimeType) {
mimeType = defaultFormat;
}
// dispatch to requested representor (or default)
switch (mimeType.toLowerCase()) {
case "application/vnd.wstl+json":
doc = wstljson(object, root);
break;
case "application/prs.links+json":
doc = jsonlinks(object, root);
break;
case "application/prs.forms+json":
doc = jsonforms(object, root);
break;
case "application/json":
doc = json(object, root);
break;
default:
doc = jsonforms(object, root);
break;
}
return doc;
}
// EOF