-
Notifications
You must be signed in to change notification settings - Fork 7
/
representor.js
67 lines (55 loc) · 1.78 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*******************************************************
* task service implementation
* 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 json = require('./representors/json.js');
var cj = require('./representors/cj.js');
var haljson = require('./representors/haljson.js');
var repjson = require('./representors/repjson.js');
var siren = require('./representors/siren.js');
// demo formats for NDC Oslo 2015
var jsonurls = require('./representors/jsonurls.js');
var jsonforms = require('./representors/jsonforms.js');
module.exports = processDoc;
function processDoc(object, mimeType, root) {
var doc;
// clueless? assume JSON
if (!mimeType) {
mimeType = "application/vnd.collection+json";
}
// dispatch to requested representor
switch (mimeType.toLowerCase()) {
case "application/json":
doc = json(object, root);
break;
case "application/vnd.collection+json":
doc = cj(object, root);
break;
case "application/vnd.hal+json":
doc = haljson(object, root);
break;
case "application/vnd.siren+json":
doc = siren(object, root);
break;
case "application/representor+json":
doc = repjson(object, root);
break;
// demo formats for NDC Oslo 2015
case "application/json;profile=urls":
doc = jsonurls(object, root);
break;
case "application/json;profile=forms":
doc = jsonforms(object, root);
break;
default:
doc = repjson(object, root);
break;
}
return doc;
}
// EOF