Comments (8)
@dougwilson I had switched from Express 3 to Express 4 and recently tried to integrate this again. After seeing this commit and the change from body
to query
, I realized I had to change my Jade form a bit. Perhaps you could add an HTML or Jade form example to the project's Readme for users to see how it's implemented on the front-end? For example, with Jade:
//- Example of an update user form
form(action='/users/' + user.id + '?_method=PUT', method='POST')
input(type='email', name='email', placeholder='email address', value=user.email, required)
button(type='submit') Update User
If this isn't right for some reason, let me know, thank you.
from method-override.
@dougwilson iirc, some browsers won't let you send a POST to a URL with a query string, so this breaks things a lot. i'm not sure though, i just use AJAX now heh
from method-override.
@niftylettuce I'll add an example of how to override the method using HTML and with XMLHTTPRequest to the docs.
@jonathanong I'm not sure where you're getting your information from for this.
some browsers won't let you send a POST to a URL with a query string, so this breaks things a lot.
Which browsers? Browsers have been doing this since the '90s, and it's part of the HTML 3.02 spec (it's hard for me to find the older specs).
If you are wondering why the change here is some history:
- This module was simply implemented almost as an example in connect, so it's decisions don't necessarily make sense
- You will find people override methods with form POST requests with query strings all over the place and I couldn't even find a method override module in another language and even checked the body.
- The biggest problem with the body, is it doesn't make sense; you have to parse the entire body up front before you do routing to be able to know what method the request is going to be. This is starting to fall over a lot with Node.js people, now that they are trying to parse their
multipart/form-data
inside an expressapp.put
, but since the method (put) is in the body of the post, it goes to the wrong handler.
TL;DR I have consulted standards and the expects in Salesforce.com before making the change and it is sound and true. If people really want body, this module is now extendable and I even but a verbatim example in the readme :)
from method-override.
If this isn't right for some reason, let me know, thank you.
What you posed is the correct way, yes.
from method-override.
@niftylettuce let me know how you feel about the updated examples: https://github.com/expressjs/method-override#examples
from method-override.
@dougwilson looks awesome! thank you 👍
from method-override.
Interesting stuff! Thanks for writing the thoughts which went into this.
Personally I'm not sure I'm going to switch from req.body parsing to req.query.
It's just exposing more details to the user and cluttering the action URL.
Parsing body upfront has never been a a big deal for me.
And yes, I've used this with multipart/form-data
(in the past, before taking the time to calculate S3 prices): if you use methodOverride before Router it just works (as expected).
Just wanted to share my point of view. Thanks for making it customizable enough to give everyone a choice :)
from method-override.
Thanks for making it customizable enough to give everyone a choice :)
Of course! I like to make stuff customizable, because I really appreciate using things that are customizable myself, as it allows me to override the author's decision, or add things the author didn't consider.
from method-override.
Related Issues (11)
- app.use() requires middleware functions HOT 5
- Case sensitive? HOT 2
- Not really an issue / more of a question HOT 1
- req.body is empty when using PUT method HOT 10
- Not an actual issue HOT 1
- Why not support this from GET? HOT 6
- Restrict HTTP method the override can arrive in HOT 2
- Method override header should be configurable
- Possible Bug: Can't get override to recognize HOT 4
- Why make the way to override method exclusive? HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from method-override.