@@ -307,13 +307,14 @@ function sendV1(req, res, next) {
307307}
308308
309309function sendV2 (req , res , next ) {
310- res .send ({hello: req .params .name });
310+ res .send ({ hello: req .params .name });
311311 return next ();
312312}
313313
314- var PATH = ' /hello/:name' ;
315- server .get ({path: PATH , version: ' 1.1.3' }, sendV1);
316- server .get ({path: PATH , version: ' 2.0.0' }, sendV2);
314+ server .get (' /hello/:name' , restify .plugins .conditionalHandler ([
315+ { version: ' 1.1.3' , handler: sendV1 },
316+ { version: ' 2.0.0' , handler: sendV2 }
317+ ]));
317318
318319server .listen (8080 );
319320```
@@ -347,25 +348,28 @@ creation time. Lastly, you can support multiple versions in the API by using
347348an array:
348349
349350``` js
350- server .get ({path: PATH , version: [' 2.0.0' , ' 2.1.0' , ' 2.2.0' ]}, sendV2);
351+ server .get (' /hello/:name' restify .plugins .conditionalHandler ([
352+ { version: [' 2.0.0' , ' 2.1.0' , ' 2.2.0' ], handler: sendV2 }
353+ ]));
351354```
352355
353356In this case you may need to know more information such as what the original
354357requested version string was, and what the matching version from the routes
355358supported version array was. Two methods make this info available:
356359
357360``` js
358- var PATH = ' /version/test' ;
359- server .get ({
360- path: PATH ,
361- version: [' 2.0.0' , ' 2.1.0' , ' 2.2.0' ]
362- }, function (req , res , next ) {
363- res .send (200 , {
364- requestedVersion: req .version (),
365- matchedVersion: req .matchedVersion ()
366- });
367- return next ();
368- });
361+ server .get (' /version/test' , restify .plugins .conditionalHandler ([
362+ {
363+ version: [' 2.0.0' , ' 2.1.0' , ' 2.2.0' ],
364+ handler : function (req , res , next ) {
365+ res .send (200 , {
366+ requestedVersion: req .version (),
367+ matchedVersion: req .matchedVersion ()
368+ });
369+ return next ();
370+ }
371+ }
372+ ]));
369373```
370374
371375Hitting this route will respond as below:
0 commit comments