Git Product home page Git Product logo

Comments (5)

adam12 avatar adam12 commented on May 20, 2024

Basically, browsers didn't (and might still) not support anything other than GET/POST (not including HEAD and OPTIONS). To work around this, Ruby on Rails started adding a _method parameter to all forms that weren't a GET or POST. This was adopted by other libraries and frameworks, and somewhat became the de-facto standard.

Unpoly works in the same way - the actual request is a POST, but with _method=PUT as a parameter.

If you're using Rack or something based off it, there is a Rack::MethodOverride middleware you can use to enable the _method param.

from unpoly.

acnebs avatar acnebs commented on May 20, 2024

Ah, I didn't realize this was a layover from Rails.

However, browsers limiting themselves to GET/POST is only applicable to HTML forms. This is an AJAX request, so it is presumably using XMLHttpRequest under the hood, which does support the PUT method.

More to the point, jQuery's $.ajax() also supports the PUT method, and since Unpoly is built on top of jQuery, it seems sensible (consistent?) to include the method in its vanilla form, rather than being wrapped in a POST.

from unpoly.

adam12 avatar adam12 commented on May 20, 2024

Yes , it was form specific. The original premise was that without Javascript, people still expected forms to submit correctly (ala, the original button_to helper in Rails).

Since Unpoly wouldn't be used without Javascript enabled, I agree that Unpoly should use the native method where possible.

But looking at the source code, it looks like this is already the case, except Unpoly makes the decision to wrap non-GET/POST methods into a POST, as you're seeing. You just need to tell Unpoly not to wrap them in a POST.

Spitballing here, but you could try this:

up.proxy.config.wrapMethods = []

from unpoly.

acnebs avatar acnebs commented on May 20, 2024

Ah, I looked into the source enough to realize that methods were being wrapped, but not closely enough to see that solution.

It worked perfectly, thank you @adam12!

from unpoly.

triskweline avatar triskweline commented on May 20, 2024

Also note that while many browsers now support verbs like PUT, PATCH, they handle redirect responses in an unexpected way.

That's another reason why many frameworks like Rails, Symfony and Express offer a way to wrap the verb in a _method param.

from unpoly.

Related Issues (20)

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.