Skip to content

Commit

Permalink
docs(req): req.getQuery() returns with a raw query string with queryP…
Browse files Browse the repository at this point in the history
…arser() plugin (#1508)
  • Loading branch information
hekike authored and DonutEspresso committed Oct 5, 2017
1 parent a9118d8 commit 8ac9cc8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
6 changes: 3 additions & 3 deletions docs/api/request.md
Expand Up @@ -96,13 +96,13 @@ req.getQuery();
// => 'a=1'
```

Note that if the query parser plugin is used, then this method will returned
the parsed query string:
If the `queryParser` plugin is used, the parsed query string is available
under the `req.query`:

```js
// incoming request is /foo?a=1
server.use(restify.plugins.queryParser());
req.getQuery();
req.query;
// => { a: 1 }
```

Expand Down
17 changes: 17 additions & 0 deletions test/plugins/query.test.js
Expand Up @@ -57,6 +57,23 @@ describe('query parser', function () {
});
});

it('req.getQuery() should return with raw query string', function (done) {
SERVER.use(restify.plugins.queryParser());

SERVER.get('/query/:id', function (req, res, next) {
assert.equal(req.getQuery(), 'a=1');
assert.deepEqual(req.query, { a: '1' });
res.send();
next();
});

CLIENT.get('/query/foo?a=1', function (err, _, res) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
done();
});
});

it('should parse req.query and req.params independently', function (done) {
SERVER.use(restify.plugins.queryParser());

Expand Down

0 comments on commit 8ac9cc8

Please sign in to comment.