Skip to content
Myr

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

3 files+57 added−6 removed

modified:docs/guide.1+24 added-2 removed
174 unmodified lines
175.176.IP "" 0177.178.P179Literal regular expressions may also be passed for complex uses:179Regular 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.nf184185app\.get(/^\\/foo(bar)?$/, function(){});185app\.get(/^\\/users?(?:\\/(\\d+)(?:\\\.\\\.(\\d+))?)?/, function(req, res, params){186 res\.send(params\.captures);187});188.189.fi190.191.IP "" 0192.193.P194Curl requests against the previously defined route:195.196.IP "" 4197.198.nf199200 $ 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.P214Below are some route examples, and the associated paths that they may consume:215.216.IP "" 4217.
892 unmodified lines
modified:docs/guide.html+17 added-2 removed
337 unmodified lines
338339<pre><code>\/user\/([^\/]+)\/?340</code></pre>341342<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 capture343groups with literal <em>RegExp</em>'s are anonymous we use the <em>params.captures</em> array.</p>344344<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>349350<p>Curl requests against the previously defined route:</p>351352<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>361362<p>Below are some route examples, and the associated paths that they363may consume:</p>364365<pre><code> "/user/:id"
590 unmodified lines
modified:docs/guide.md+16 added-2 removed
98 unmodified lines
99when _/user/:id_ is compiled, a simplified version of the regexp may look similar to:100101 \/user\/([^\/]+)\/?102103Literal regular expressions may also be passed for complex uses:103Regular expression literals may also be passed for complex uses. Since capture104groups with literal _RegExp_'s are anonymous we use the _params.captures_ array.105105 app.get(/^\/foo(bar)?$/, function(){});106 app.get(/^\/users?(?:\/(\d+)(?:\.\.(\d+))?)?/, function(req, res, params){107 res.send(params.captures);108 });109110Curl requests against the previously defined route:111112 $ 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"]120121Below are some route examples, and the associated paths that they122may consume:123124 "/user/:id"
518 unmodified lines