0

Why will this code respond to the request while the below one is not supported?

---------------------------These are supported-------------------------

app.put('/dishes/:dishId', (req, res, next) => {
  res.write('Updating the dish: ' + req.params.dishId + '\n');
  res.end('Will update the dish: ' + req.body.name + 
        ' with details: ' + req.body.description);
});


app.post('/dishes', (req, res, next) => {
 res.end('Will add the dish: ' + req.body.name + ' with details: ' + req.body.description);
});

---------------------------These are not supported------------------------

 app.put('/dishes', (req, res, next) => {
  res.statusCode = 403;
  res.end('PUT operation not supported on /dishes');
});

 app.post('/dishes/:dishId', (req, res, next) => {
  res.statusCode = 403;
  res.end('POST operation not supported on /dishes/'+ req.params.dishId);
});
Mahamat
  • 321
  • 4
  • 14
  • the below just dosent feel right it does not define the operation properly and you will always put/post for a particular dish and not for dishes. – Rahul Singh Dec 11 '17 at 16:12
  • What do you mean by "not supported"? Also, I know that you are using different methods (PUT, POST, etc), but be mindful that route definitions are order dependent. See: https://stackoverflow.com/q/32603818/691711. – zero298 Dec 11 '17 at 16:18

0 Answers0