-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.js
39 lines (35 loc) · 914 Bytes
/
example.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
var rest = require('./lib/rest');
var sys = require('sys');
var people = [
{id: 0, name: "Adam Williams"},
{id: 1, name: "Brian Smith"},
{id: 2, name: "Kate Bowers"}
];
// resources
rest
.path("/person/{id}")
.method("GET")
.as(function(req, resource) {
var personId = parseInt(req.pathParam("id"));
sys.log("incoming request for person id: " + personId);
if(typeof people[personId] === "undefined") {
resource.notFound();
} else {
resource.ok(people[personId]);
}
});
// list of references to resources
rest
.path("/person_ref")
.method("GET")
.as(function(req, resource) {
resource.ref(people, 'id', '/person/{id}');
});
// list of resources
rest
.path("/person")
.method("GET")
.as(function(req, resource) {
resource.ok(people);
});
rest.start(8088);