Skip to content
Myr

Docs

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 4e41c35 · Browse files · 2 files+19 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+19 added−1 removed

  • tests:+12 added−0 removed
  • other:+7 added−1 removed

2 files+19 added−1 removed

modified:docs/guide.md+7 added-1 removed
96 unmodified lines
9798 \/user\/([^\/]+)\/?99100Regular expression literals may also be passed for complex uses. Since capture101groups with literal _RegExp_'s are anonymous we can access them directly `req.params`.101groups with literal _RegExp_'s are anonymous we can access them directly `req.params`. So our first capture group would be _req.params[0]_ and the second would follow as _req.params[1]_.102103 app.get(/^\/users?(?:\/(\d+)(?:\.\.(\d+))?)?/, function(req, res){104 res.send(req.params);105 });
38 unmodified lines
144 "/products.:format?"145 /products.json146 /products.xml147 /products148 149 "/user/:id.:format?"150 /user/12151 /user/12.json152153For example we can __POST__ some json, and echo the json back using the _bodyDecoder_ middleware which will parse json request bodies (as well as others), and place the result in _req.body_:154155 var express = require('express')
6 unmodified lines
162 });163164 app.listen(3000);165166Express 2.0.0-pre also supports named capture groups. Typically we may use a "dump" placeholder such as "/user/:id" which has no restraints, however say for example we are limiting a user id to digits, we may use _/user/:id(\d+)_ which will _not_ match unless the placeholder value contains only digits.167168### Passing Route Control169170We may pass control to the next _matching_ route, by calling the _third_ argument,171the _next()_ function. When a match cannot be made, control is passed back to Connect,
879 unmodified lines
modified:test/express.test.js+12 added
423 unmodified lines
424 { body: 'OK', status: 200 });425 });426 },427 428 'test named capture groups': function(){429 var app = express.createServer();430431 app.get('/user/:id(\d+)', function(req, res){432 res.send('user ' + req.params.id);433 });434435 assert.response(app,436 { url: '/user/12' },437 { body: 'user 12' });438 },439 440 'test .param()': function(){441 var app = express.createServer();442443 var users = [
42 unmodified lines