forked from ringo/stick
/
index.html
171 lines (144 loc) · 8.1 KB
/
index.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
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
<!DOCTYPE html >
<html lang="de" dir="ltr">
<head>
<title>stick/middleware/route - Stick API</title>
<link rel="shortcut icon" href="http://ringojs.org/favicon.ico" type="image/x-icon" />
<link rel="icon" href="http://ringojs.org/favicon.ico" type="image/x-icon" />
<link rel="stylesheet" href="../../static/style.css" />
<link rel="stylesheet" href="../../static/jsdoc.css" />
<script type="text/javascript" src="../../static/jquery.js"></script>
<script type="text/javascript" src="../../static/jsdoc.js"></script>
<script>
$(document).ready(jsdocSetup);
</script>
</head>
<body>
<div class="wrap">
<div class="main">
<div class="content">
<h1 class="modulename">Module stick/middleware/route</h1>
<div class="fileoverview">
<p>Middleware for HTTP method based local request routing.</p>
<p>This installs <code>get</code>, <code>post</code>, <code>put</code>, and <code>del</code> methods in the application
object for routing requests with the corresponding HTTP methods. These
methods take a path spec as first argument and a function as second argument.</p>
<h3>Paths and Placeholders</h3>
<p>The path spec can consist of static parts and placeholders.
Named placeholders are prefixed by <code>:</code> (colon) and match all
characters except for <code>/</code> (slash) and <code>.</code> (dot). A named
placeholder can be marked as optional by appending <code>?</code> (question mark).
Unnamed placeholders are denoted by the asterisk character <code>*</code> and match
all characters including slashes and dots.</p>
<p>In the following example, ":id" is a named placeholder:</p>
<pre><code>"/post/:id"</code></pre>
<p>All placeholders are passed to the action function as positional arguments
following the request object in the order in which they appear in the path spec.
Unmatched optional placeholders will be <code>undefined</code>.</p>
<pre><code>app.get("/post/:id", function(req, id) {...});</code></pre>
<h3>Reverse Routing</h3>
<p>The route middleware supports generating URLs from route names and parameters
required by the route.</p>
<p>Routes names are derived from the route's path spec by stripping
out all placeholders and removing a leading slash. For example, a path
spec <code>/post/:id.html</code> results in route name "post.html". If a path spec
does not contain any static part, its route name is "index".</p>
<p>Passing a valid route name and the parameters required by the route to the <code>route.reverse</code>
method will return the URI path for the corresponding action. For example,
with a route spec <code>/post/:id.html</code>, calling <code>app.route.reverse({action: "post.html", id: 5})</code>
will return the string "/post/5.html".</p>
<p>The <a href="../../helpers/index.html" title="helpers">stick/helpers</a> module provides higher level helpers for reverse
routing including support for mounted applications.</p>
</div>
<div>
<h4> Example </h4>
<pre class="sh_javascript sh_sourceCode">app.configure("route")
app.get("/", function() {...})
app.post("/", function(req) {...})
app.get("/:id.:format?", function(req, id, format) {...})
app.del("/:id", function(req, id) {...})
app.put("/:id", function(req, id) {...})</pre>
</div>
<div class="classoverview">
<div>
<h3>Functions</h3>
<ul class="propertyoverview">
<li>
<a href="#middleware" class="jsdoc-title"> middleware</a>(next, app)
</li>
</ul>
</div>
<div class="classes">
</div>
</div>
<hr/>
<div class="details">
<!-- tpl-docitem -->
<div>
<div class="docitem" docitem="middleware">
<h3>
<span class="itemtitle"><a id="middleware" href="#middleware" class="itemtitle itemname">middleware</a></span>
<span class="itemtitle light">(next, app)</span></h3>
<div>
<p>Middleware for HTTP method based local request routing.</p>
</div>
<div>
<h4>Parameters</h4>
<table>
<tr>
<td>Function</td>
<td class="paramname">next</td>
<td>the wrapped middleware chain</td>
</tr>
<tr>
<td>Object</td>
<td class="paramname">app</td>
<td>the Stick Application object</td>
</tr>
</table>
</div>
<div>
<h4>Returns</h4>
<table>
<tr>
<td>Function</td>
<td> a JSGI middleware function</td>
</tr>
</table>
</div>
</div>
<hr/>
</div>
</div>
</div>
</div>
<div class="menu" style="margin-top: 1em; font-size: 13px;">
Stick API<br/>
<a href="../../index.html">Module list</a>
<a href="../../index_all.html">Full index</a><br/>
<input id="jsdoc-leftnavsearch" type="search" placeholder="Filter module list" size="14">
<ul class="jsdoc-leftnav leftnav">
<li><a href="../../stick/index.html"> stick </a></li>
<li><a href="../../helpers/index.html"> stick/helpers </a></li>
<li><a href="../../middleware/index.html"> stick/middleware </a></li>
<li><a href="../../middleware/basicauth/index.html"> stick/middleware/basicauth </a></li>
<li><a href="../../middleware/continuation/index.html"> stick/middleware/continuation </a></li>
<li><a href="../../middleware/cookies/index.html"> stick/middleware/cookies </a></li>
<li><a href="../../middleware/error/index.html"> stick/middleware/error </a></li>
<li><a href="../../middleware/etag/index.html"> stick/middleware/etag </a></li>
<li><a href="../../middleware/gzip/index.html"> stick/middleware/gzip </a></li>
<li><a href="../../middleware/method/index.html"> stick/middleware/method </a></li>
<li><a href="../../middleware/mount/index.html"> stick/middleware/mount </a></li>
<li><a href="../../middleware/notfound/index.html"> stick/middleware/notfound </a></li>
<li><a href="../../middleware/params/index.html"> stick/middleware/params </a></li>
<li><a href="../../middleware/profiler/index.html"> stick/middleware/profiler </a></li>
<li><a href="../../middleware/render/index.html"> stick/middleware/render </a></li>
<li><a href="../../middleware/requestlog/index.html"> stick/middleware/requestlog </a></li>
<li><a href="../../middleware/route/index.html"> stick/middleware/route </a></li>
<li><a href="../../middleware/session/index.html"> stick/middleware/session </a></li>
<li><a href="../../middleware/static/index.html"> stick/middleware/static </a></li>
<li><a href="../../middleware/upload/index.html"> stick/middleware/upload </a></li>
</ul>
</div>
</div>
</body>
</html>