My Profile Photo

Rich Werden

Web Developer & Software Engineer


A site for Rich to write about code and show some completed projects for future reference...


#TIL: Handling GET and POST on the same endpoint

Today’s TIL: You can use app.route() for handling both GET and POST requests on the exact same endpoint in Express: Just chain them together after using app.route('/endpoint') like so…

app
  .route('/things')
  .get(function (req, res) {
    res.send('Get a thing');
  })
  .post(function (req, res) {
    res.send('Add a thing');
  })
  .put(function (req, res) {
    res.send('Update a thing');
  });

Keepin’ it clean…