Hacker News new | ask | show | jobs
by nickjj 1212 days ago
I like using `rails middleware` as an example because it's true, tons of things in that list are important.

A good example of this is: Rack::MethodOverride

Try making your non-JS server rendered view functions and HTML form submissions handle PUT, PATCH and DELETE. Depending on which lightweight alternative to Rails you're using this can become very tricky and you end up spending an entire day of Googling and maybe finding a questionable solution instead of having that available without thinking about it.

1 comments

Unless I’m misunderstanding you, this is trivial in every stack I’ve used (.NET, Node, Rails, and Go). I can’t imagine why this would be difficult.
> Unless I’m misunderstanding you, this is trivial in every stack I’ve used (.NET, Node, Rails, and Go). I can’t imagine why this would be difficult.

It's trivial in Rails because the middleware mentioned handles it.

Forms only allow GET and POST if you submit it from a browser without JavaScript. That means you need to do things like introduce a hidden form field such as _method with the real method you want to use such as PATCH and then your framework's middleware level needs to understand how to translate that to call the correct function to handle the request. There's all sorts of edge cases around dealing with files and detecting if the request needs to be translated, etc..

With Flask this is a huge clusterfuck, https://blog.carsonevans.ca/2020/07/06/request-method-spoofi... has a breakdown on how it's anything but trivial. Sure there's https://flask.palletsprojects.com/en/2.2.x/patterns/methodov... but this involves setting a header which implies it's submit through JavaScript or another service over an API but in our case we want to submit it through a browser without using JavaScript.