Repository navigation
Expand file tree
/
Copy pathjsonrpc.html
More file actions
181 lines (172 loc) · 5.34 KB
/
Copy pathjsonrpc.html
File metadata and controls
181 lines (172 loc) · 5.34 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<!DOCTYPE html>
<html>
<head>
<title>Connect</title>
<meta http-equiv="content-type" value="text/html; charset=utf-8">
<style type="text/css">
body {
font: 13px "Helvetica Neue", "Lucida Grande", "Arial";
text-align: center;
color: #555;
-webkit-text-stroke: 1px rgba(255, 255, 255, 0.1);
}
h1, h2, h3 {
margin: 0;
font-size: 22px;
font-weight: normal;
color: #343434;
}
h2#Connect {
margin-bottom: 25px;
font-size: 60px;
font-weight: bold;
}
h2#Connect + p {
display: none;
}
h3 {
margin: 35px 0;
padding-left: 10px;
font-size: 16px;
border-left: 15px solid #eee;
}
h2 {
margin-top: 35px;
text-shadow: 1px 2px 2px #ddd;
}
ul {
margin: 10px 35px;
padding: 0;
}
ul li .path {
padding-left: 5px;
font-weight: bold;
}
ul li .line {
padding-right: 5px;
font-style: italic;
}
ul li:first-child .path {
padding-left: 0;
}
p {
line-height: 1.5;
}
p code {
padding: 2px 4px;
border: 1px solid #ddd;
}
p em, li em {
font-weight: bold;
}
pre {
margin: 25px 0 25px 15px;
padding: 15px;
border: 1px solid #ddd;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
-webkit-box-shadow: 1px 1px 6px #ddd;
-moz-box-shadow: 1px 1px 6px #ddd;
}
table {
margin-bottom: 35px;
width: 100%;
border-collapse: collapse;
}
table td {
padding: 5px 10px;
font-size: 14px;
}
table tr {
border-bottom: 1px solid #fff;
}
table tr:last-child {
border-bottom: none;
}
table td:first-child {
width: 150px;
color: #343434;
}
#wrapper {
margin: 50px auto;
width: 750px;
text-align: left;
}
#menu {
position: fixed;
top: 15px;
right: 15px;
margin: 0;
padding: 0;
list-style: none;
text-align: right;
}
#menu li.title {
padding: 20px 0 5px 0;
font-size: 12px;
}
code.js { color: #111; }
code.js .comment { color: #999; }
code.js .string { color: #cc0000; }
code.js .number { color: #0000ee; }
code.js .keyword { color: #000; font-weight: bold; }
a {
text-decoration: none;
color: #000;
}
a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div id="wrapper">
<ul id="menu">
<li class="title">API</li>
<li><a href="api.html">extended api docs</a></li>
<li class="title">Middleware</li>
<li><a href="lint.html">lint</a></li>
<li><a href="logger.html">logger</a></li>
<li><a href="router.html">router</a></li>
<li><a href="jsonrpc.html">jsonrpc</a></li>
<li><a href="session.html">session</a></li>
<li><a href="compiler.html">compiler</a></li>
<li><a href="errorHandler.html">errorHandler</a></li>
<li><a href="bodyDecoder.html">bodyDecoder</a></li>
<li><a href="responseTime.html">responseTime</a></li>
<li><a href="cookieDecoder.html">cookieDecoder</a></li>
<li><a href="conditionalGet.html">conditionalGet</a></li>
<li><a href="methodOverride.html">methodOverride</a></li>
<li><a href="staticProvider.html">staticProvider</a></li>
</ul><div class='mp'>
<h2 id="JSON-RPC">JSON-RPC</h2>
<p>The <em>jsonrpc</em> middleware provides JSON-RPC 2.0 support. Below is an example exposing the <em>add</em> and <em>sub</em> methods:</p>
<pre><code class="js"><span class="keyword">var</span> <span class="variable">math</span> = {
<span class="variable">add</span>: <span class="keyword">function</span>(<span class="variable">a</span>, <span class="variable">b</span>, <span class="variable">fn</span>){
<span class="variable">fn</span>(<span class="keyword">null</span>, <span class="variable">a</span> + <span class="variable">b</span>);
},
<span class="variable">sub</span>: <span class="keyword">function</span>(<span class="variable">a</span>, <span class="variable">b</span>, <span class="variable">fn</span>){
<span class="variable">fn</span>(<span class="keyword">null</span>, <span class="variable">a</span> - <span class="variable">b</span>);
}
};
<span class="keyword">var</span> <span class="variable">date</span> = {
<span class="variable">time</span>: <span class="keyword">function</span>(<span class="variable">fn</span>){
<span class="variable">fn</span>(<span class="keyword">null</span>, <span class="keyword">new</span> <span class="class">Date</span>().<span class="variable">toUTCString</span>());
}
};
<span class="variable">connect</span>.<span class="variable">createServer</span>(
<span class="variable">connect</span>.<span class="variable">jsonrpc</span>(<span class="variable">math</span>, <span class="variable">date</span>)
);
</code></pre>
<p>When you wish to pass an exception simply invoke <code>fn(err)</code>, or pass the error code <code>fn(jsonrpc.INVALID_PARAMS)</code>. Otherwise <code>fn(null, result)</code> will respond with the given results.</p>
<h3 id="Features">Features</h3>
<ul>
<li>async support</li>
<li>batch request support</li>
<li>variable argument length</li>
<li>named parameter support</li>
</ul>
</div>
</div>
</body>
</html>