This repository was archived by the owner on Feb 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbasic.html
70 lines (61 loc) · 1.6 KB
/
basic.html
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
68
69
70
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src="../components/rhumb/dist/rhumb.js"></script>
<script type="text/javascript" src="../src/nap.js"></script>
<script type="text/javascript" src="../lib/d3/d3.js"></script>
<script type="text/javascript">
function init(){
var ok = nap.responses.ok
, into = nap.into
function bar(req, res){
console.log("called", req.uri, req.params)
res(false, ok("bar called"))
}
function foo(req, res){
console.log("called", req.uri, req.params)
res(false, ok("foo called"))
}
function speak(req, res){
res(
false
, ok(function(node) {
d3.select(node).text(req.params.name)
})
)
}
// setup this web
var web = nap.web()
.resource("/foo/bar", bar)
.resource("/foo/{thing}/wibble", foo)
.resource("/speak/{name}", speak)
// make some requests
web.req("/foo/bar", function(err, res) {
console.log(res.body)
})
web.req("/foo/chips/wibble", function(err, res) {
console.log(res.body)
})
// create some views from requests
d3.select(".message")
.selectAll("li")
.data(
[ "/speak/sammy"
, "/speak/becky"
, "/speak/zia"
]
)
.enter().append("li")
.each(function(d, i) {
web.req(d, into(this))
})
}
</script>
<title>Basic</title>
</head>
<body onload="init()">
<ul class="message">
</ul>
</body>
</html>