3

Is there an easy way to have yesod read a POST request as a PUT or DELETE when it has a special parameter: _method=DELETE? And render forms with it?

1 Answer 1

2

Yesod uses the methodOverride middleware by default which allows this. When I use this approach, I just put it into the action attribute of the form, e.g.:

<form method=post action=@{SomeRouteR}?_method=DELETE>
4
  • Hmm, I tried this and it still goes through as a POST.
    – user316146
    Apr 9, 2014 at 1:23
  • It works with a standard setup, e.g. fpcomplete.com/user/snoyberg/random-code-snippets/…. You might have different middlewares configured, but I can't tell from the information you've provided. Apr 9, 2014 at 4:33
  • 1
    I just ran into the fact myself that the scaffolded site does not have methodOverride enabled by default. If that's the issue you're running into, you need to edit your Application.hs, find the code that says logWare app, and replace it with logWare $ methodOverride app. You'll need to include an import for Network.Wai.Middleware.MethodOverride as well. Apr 9, 2014 at 10:53
  • Yep, that was the issue. Thanks! :)
    – user316146
    Apr 9, 2014 at 22:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.