Question

in the express generated code:

...
app.use(express.urlencoded());
app.use(express.methodOverride());
app.use(express.cookieParser('my secret cat'));
...

express.methodOverride() is unfamilar to me. I read the doc Connect document here, but still miss the whole picture.

My question is:

In what situation do we need to override a method(GET, POST, PUT, and DELETE) using express.methodOverride()?

I found an relevant answer here, but my follow up question is:

If no express.methodOverride(), I can't use app.put(), app.delete(), app.get(), app.post() in Express. Is this correct?

Was it helpful?

Solution

methodOverride is an affordance for browser forms submitted with a standard form submission that can only use the GET or POST methods. Also, it seems Adobe Flex also was limited in the HTTP methods it could send. See this answer for some details. If you are using XmlHttpRequest (AJAX) interaction with your server, browsers these days can do all the REST methods just fine.

The takeaway is always code your express code with the full set of REST methods, app.put, app.del, etc. If you are doing <form> tag submissions, then use methodOverride as well and all will be well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top