Docs for params.captures. Closes #358
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent 4d32762 · Browse files · 3 files·+57 added−6 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+57 added−6 removed
- other:+57 added−6 removed
Provenance
- Commit
d03821b- Tree
ad53e25- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
4d32762
3 files changed+57 added−6 removed
modified:docs/guide.1+24 added-2 removed
174 unmodified lines175 .176 .IP "" 0177 .178 .P179-Literal regular expressions may also be passed for complex uses:179+Regular expression literals may also be passed for complex uses\. Since capture groups with literal \fIRegExp\fR\'s are anonymous we use the \fIparams\.captures\fR array\.180 .181 .IP "" 4182 .183 .nf184 185-app\.get(/^\\/foo(bar)?$/, function(){});185+app\.get(/^\\/users?(?:\\/(\\d+)(?:\\\.\\\.(\\d+))?)?/, function(req, res, params){186+ res\.send(params\.captures);187+});188 .189 .fi190 .191 .IP "" 0192 .193 .P194+Curl requests against the previously defined route:195+.196+.IP "" 4197+.198+.nf199+200+ $ curl http://dev:3000/user201+ [null,null]202+ $ curl http://dev:3000/users203+ [null,null]204+ $ curl http://dev:3000/users/1205+ [\"1\",null]206+ $ curl http://dev:3000/users/1\.\.15207+ [\"1\",\"15\"]208+.209+.fi210+.211+.IP "" 0212+.213+.P214 Below are some route examples, and the associated paths that they may consume:215 .216 .IP "" 4217 .892 unmodified linesmodified:docs/guide.html+17 added-2 removed
337 unmodified lines338 339 <pre><code>\/user\/([^\/]+)\/?340 </code></pre>341 342-<p>Literal regular expressions may also be passed for complex uses:</p>342+<p>Regular expression literals may also be passed for complex uses. Since capture343+groups with literal <em>RegExp</em>'s are anonymous we use the <em>params.captures</em> array.</p>344 344-<pre><code>app.get(/^\/foo(bar)?$/, function(){});345+<pre><code>app.get(/^\/users?(?:\/(\d+)(?:\.\.(\d+))?)?/, function(req, res, params){346+ res.send(params.captures);347+});348 </code></pre>349 350+<p>Curl requests against the previously defined route:</p>351+352+<pre><code> $ curl http://dev:3000/user353+ [null,null]354+ $ curl http://dev:3000/users355+ [null,null]356+ $ curl http://dev:3000/users/1357+ ["1",null]358+ $ curl http://dev:3000/users/1..15359+ ["1","15"]360+</code></pre>361+362 <p>Below are some route examples, and the associated paths that they363 may consume:</p>364 365 <pre><code> "/user/:id"590 unmodified linesmodified:docs/guide.md+16 added-2 removed
98 unmodified lines99 when _/user/:id_ is compiled, a simplified version of the regexp may look similar to:100 101 \/user\/([^\/]+)\/?102 103-Literal regular expressions may also be passed for complex uses:103+Regular expression literals may also be passed for complex uses. Since capture104+groups with literal _RegExp_'s are anonymous we use the _params.captures_ array.105 105- app.get(/^\/foo(bar)?$/, function(){});106+ app.get(/^\/users?(?:\/(\d+)(?:\.\.(\d+))?)?/, function(req, res, params){107+ res.send(params.captures);108+ });109 110+Curl requests against the previously defined route:111+112+ $ curl http://dev:3000/user113+ [null,null]114+ $ curl http://dev:3000/users115+ [null,null]116+ $ curl http://dev:3000/users/1117+ ["1",null]118+ $ curl http://dev:3000/users/1..15119+ ["1","15"]120+121 Below are some route examples, and the associated paths that they122 may consume:123 124 "/user/:id"518 unmodified lines