What does Connect.js methodOverride do?

node.jsconnect.js

node.js Problem Overview


The Connect.js very terse documentation says methodOverride

> Provides faux HTTP method support.

What does that mean? The obvious Google search is less than helpful. Why is methodOverride useful?

node.js Solutions


Solution 1 - node.js

  • If you want to simulate DELETE and PUT, methodOverride is for that.
  • If you pass in the _method post parameter set to 'delete' or 'put', then you can use app.delete and app.put in Express instead of using app.post all the time (thus more descriptive, verbose):

Backend:

// the app
app.put('/users/:id', function (req, res, next) {
  // edit your user here
});

Client logic:

// client side must be..
<form> ...
  <input type="hidden" name="_method" value="put" />
</form>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRandomblueView Question on Stackoverflow
Solution 1 - node.jsalessioalexView Answer on Stackoverflow