To use a header to override the method, specify the header name as a string argument to the methodOverride function. To then make the call, send a POST request to a URL with the overridden method as the value of that header.
The methodOverride() middleware is for requests from clients that only natively support simple verbs like GET and POST. So in those cases you could specify a special query field (or a hidden form field for example) that indicates the real verb to use instead of what was originally sent.
What is connect? From the README: Connect is an extensible HTTP server framework for node, providing high performance "plugins" known as middleware. More specifically, connect wraps the Server, ServerRequest, and ServerResponse objects of node.
Connect also offers a createServer method, which returns an object that inherits an extended version of http. Server . Connect's extensions are mainly there to make it easy to plug in middleware. That's why Connect describes itself as a "middleware framework," and is often analogized to Ruby's Rack.
DELETE
and PUT
, methodOverride
is for that.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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With