Rest api implementation with parameter using JetBrains WebStorm + node.js + express -


first of all, i'm using jetbrains webstorm , used create node.js express app project.

my modifications @ app.js

app.get('/api/restaurants', function(req, res) {   console.log("parameter[0]", req.params.restaurant_id);   res.json({     '01010112d8139f13': '0ao123r1'   }); }); app.get('/api/restaurants/:id', function(req, res) {   console.log("parameter[1]", req.params.restaurant_id);   res.json({     'message': 'worked?'   }); }); 

i'm using postman plugin @ chrome test api , can't access localhost:3000/api/restaurants?restaurant_id=01010112d8139f13 without being routed router.route('/restaurants') instead of router.route('/restaurants/:restaurant_id')

at console have:

get /api/restaurants?id=01010112d8139f13 200 1.803 ms - 31 

if can me, in advance.

restaurant_id not query parameter variable part in path. example /restaurants/01010112 , /restaurants/1 both handled same web request handler because both fit on /restaurants/:restaurant_id pattern.

the restaurant specific endpoint need modified following way:

app.get('/api/restaurants/:id', function(req, res) {   console.log("parameter[1]", req.params.id);   res.json({     'message': 'worked?'   }); }); 

and use following url on console:

/api/restaurants/01010112d8139f13


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -