Giter Site home page Giter Site logo

Comments (8)

niftylettuce avatar niftylettuce commented on April 27, 2024

@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.

jonathanong avatar jonathanong commented on April 27, 2024

@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.

dougwilson avatar dougwilson commented on April 27, 2024

@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:

  1. This module was simply implemented almost as an example in connect, so it's decisions don't necessarily make sense
  2. 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.
  3. 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 express app.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.

dougwilson avatar dougwilson commented on April 27, 2024

@niftylettuce

If this isn't right for some reason, let me know, thank you.

What you posed is the correct way, yes.

from method-override.

dougwilson avatar dougwilson commented on April 27, 2024

@niftylettuce let me know how you feel about the updated examples: https://github.com/expressjs/method-override#examples

from method-override.

niftylettuce avatar niftylettuce commented on April 27, 2024

@dougwilson looks awesome! thank you 👍

from method-override.

framp avatar framp commented on April 27, 2024

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.

dougwilson avatar dougwilson commented on April 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.