What does Connect.js methodOverride do?
-
28-10-2019 - |
문제
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?
해결책
- If you want to simulate
DELETE
andPUT
,methodOverride
is for that. - If you pass in the _method post parameter set to 'delete' or 'put', then you can use
app.delete
andapp.put
in Express instead of usingapp.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>
제휴하지 않습니다 StackOverflow