Rails 4.0: PATCH will replace PUT as the primary HTTP method for updates
weblog.rubyonrails.org
weblog.rubyonrails.org
Why are they even bothering? Really, who cares about PATCH vs. PUT? If PATCH even has a remote chance of breaking 0.01% of sites, then WHY do it? PUT works fine. I don't care. I don't care either way, actually, since I don't use Rails anymore, just put PATCH in.
But my main concern is: Why is this major blog post worthy for Rails? I want to see something like "Rails 4: Damn Simple Websockets" or something to show that Rails is modernizing. I spent some time playing (read: nothing serious) with Lift and Scala, and while I wouldn't use that full time, it is clear to see that Lift has a handful of features that are just amazing for a modern website that Rails completely lacks (ridiculously simple AJAX/websocket stuff, triggering UI elements based on data model changes in the backend, etc.).
Anyways, its so early that Rails 4 is still a big unknown, but this is not the PR start I would've liked to see.
Well, this "if it even remotely breaks 0.01%" and "I don't care" attitude is the main reason things get bloated and stop progressing.
There's still serious performance regressions.
The asset pipeline is still sort of a trainwreck.
There's still no automation for schema migrations (perhaps hobo fields will finally bring some relief for those who adopt it).
They still don't seem to have realized that code generators are a no-go.
I see zero efforts towards modernizing the bloated routing and MVC cruft to accomodate modern fat-clients (and imho the "resources"-magic was a terrible idea from the start even for regular apps).
The whole thing is still riddled with ungodly amounts of magic that likes to break in unpredictable ways (my pet bug: the monkey-patch to really suppress browser stack-traces in production changes about every 3 months and it's worrying such a bug was deliberately created in first place).
I could go on for a while... </rant>
To be able to change the direction of Rails on this issue and the other issues the poster above raised, I'd have to spend a significant amount of time submitting patches and get to the point where I am a major committer to have the opportunity to chime in and have a significant impact on the direction Rails is going. Even if I or someone else with the same concerns were committed to making that effort, by the time I or they get to the point where we can have an impact, it will be too late.
I'd rather commit to a node or an npm package than rails because any package I commit to will hopefully be replaced by something better once it's outlived its usefulness. My favorite part about node is that it isn't opinionated. It leaves the opinion to the community modules. Hopefully most community modules with maintain just the right amount of opinion about their domain and know when to concede matters of opinion to other modules that node better. It's nice when separation of concerns is a cultural value.
This isn't a node/rails debate. It's a values debate. I think opinion was the right value for the right time several years ago. We're going through a time of change where opinion is a liability not an asset.
I know that GIT and the like have made it really easy to fork and run, but does this fundamentally help? Does having X versions of some framework really make sense?
Why not go a different route and just give up the one side and make another? Rather than forking, make something new.
Personally, I think there's not. I think people either are sticking to Rails or they are not. I think even if you don't like the new Rails, it did help the development community at large. Before Rails, I don't know many web folks who were talking about TDD and MVC and real, honest, programming stuff.
Yes, it does. What ends up happening in practice is that forks are almost always short-lived. They either get merged with the mainline, they become the new mainline, or they die out. Occasionally, there are two self-sustaining projects that diverge from the same point of origin, but it's rare.
Node is not opinionated because it is not a framework; it is a JavaScript environment built on V8 and some common libraries. It would be much more appropriate to compare Express* with Rails than Node with Rails.
If you want to compare Node with something you'd be more correct comparing Node and its modules with Ruby and its gems.
* Even though, from what I can see, Express has more in common with Sinatra than Rails...
Express knows where its "opinion" ends and where it should make room for other modules with opinions of their own.
There really are two opinions at play here. Opinions of how to do something and opinions of what to do.
Express has opinions of how that differ from the http module (it even uses the http module to accomplish what it does).
Express has a minor opinion on what it should be doing and extends the what beyond the http module, but that's largely where it ends.
The problem with Rails is that it the domain of subjects it had an opinion on kept growing until it couldn't not have an opinion on stuff.
CSS versus SASS? I love Sass and used it before Rails added it. Rails didn't need to have an opinion here. Coffeescript? Same thing.
Maybe it is an unfair comparison because there's no equivalent to this much opinion about so many things in the Javascript world, except some Rails ports that people have made. And even they are seen by most as "Oh that's nice that you can get set up quickly in less than a day, but no thanks, I'd like to pick and choose what makes sense to me based on what I'm planning on building."
Had we known better maybe we would have gone with Sinatra back when we started.
Given what you've described I'd suggest you take just one more friendly unbiased look at Rails 3... and if after that it's still not your cup of tea then fair is fair. Maybe you won't choose to develop with it, but maybe you also won't choose bash it. It's pretty cool and I believe it was an attempt by Rails developers to address your very concerns. Most major components can now be easily swapped via Railties thanks to the decoupling efforts.
The architecture, like railties look pretty cool, but policy of constantly embrace and extend just leads to bloat that gets in the way when you're doing something more exotic than straight server-side CRUD.
I think this may be becoming more true everyday, but I still don't think we've come to the point where anyone has discovered The Way to do web stuff. Rails continues to introduce ideas that are interesting and important. Would CoffeeScript and Sass have received such rapid uptake if not for Rails? (Some of you may think that would be a good thing)
TDD as a cultural norm was Rails' biggest contribution. That was a good thing and was an opinion that few developers with argue with.
Maybe your experience with open-source is different. I think most contributors do it for joy, anyway.
Demanding unpaid labour has nothing to do with you or anyone else volunteering labour. My words cannot possibly be construed as saying volunteer work in open source is slavery.
"I do not believe that engineers creating software for other engineers results in exploitation."
Squeaky wheel driven development is not slavery. Users are "free" to demand features, and developers are "free" to ignore the requests. Your premise is absurd.
Similarly, cheald does not demand that users of open source projects contribute fixes for bugs. He also only stated that the exact opposite attitude is not a good idea.
Arguing either of those extremes is pointless: the discussion starts polarized and neither side will yield an inch. Introducing slavery into the discussion doesn't help.
Most authors of open source projects are interested in having their projects be used by many others. It is the usefulness to many others that provides a sense of accomplishment. If they don't pay some attention to problems those others encounter and for instance fix clear bugs in early releases, their chances of achieving that goal are lower. Observing this fact about the system is not argument in favor of slavery. There are no normative statements involved.
Similarly, if you, as a user of an open source project, want some bug fixed, the best way to go about it is often to write the code yourself and offer it for inclusion. That suggestion does not reduce them to slaves either.
To make a bazaar work, all parties involved have to be flexible in their expectations.
The number of patches that get rejected is staggering. Practice shows that 'patches welcome' is just not true.
It's beyond me why rails thinks it should dictate how to write/manage/package javascript.
As a newbie-ish javascript developer I am continually learning from great projects like requirejs, enderjs, nodejs, commonjs (AMD in general), backbonejs, etc.
How arrogant do rails programmers have to be to dip their hand into javascript best practices? Honest question, because the better I get at programming the more I feel like rails is less necessary.
Bottom line is Rails is, and always has been, and opinionated framework, which you choose to buy in to. And even in recent years they've been better about letting you opt out of certain parts of it.
The asset pipeline is not arrogance it's convenience. If you have a better system for those tasks then you shouldn't use the pipeline, but for a lot of people the asset pipeline saves time and results in a faster, better experience for their end users.
Bundling a default that doesn't play well with lots of the client-side innovations hurts rails more than helps.
The asset pipeline as it is currently designed is monolithic and an all or nothing approach.
An insistence on handling all things with Ruby is why things get bloated and stop progressing.
Sprockets solves a pain, I admit, but at the cost of adding ruby bloat to all thick client code.
Instead of being able to use javascript libraries with one another natively, everything goes through Ruby.
Anyways, I'll probably get downvoted for this comment by Railers because this is somewhat OT and trollish (I admit), but it's a legitimately complaint about the direction of Rails.
I think Rails has lost sight of what it does really well, server-side logic. Rails, in v4.0, needs to adopt a symbiotic relationship with thick-client javascript instead of trying to consume it and insert ruby in-between all the javascript parts.
For example, right now, the recommended place for a backbone.js app in a rails project is /app/assets/javascripts/. That "folder" is only going to grow as the client-side javascript becomes more important. Keeping the javascript logic "subordinate" to the Ruby elements in a Rails project causes more bloat than anything else. Look at any thick-client Rails project and count the number of gems managing javascript. If there are more than two or three, you've probably got a separation of concerns issue at the language level. That's bloat.
If you want to down vote me, go ahead. I just ask that you have the courtesy to defend your down vote with a comment. If you think I'm wrong tell me why. Maybe, I'm doing something wrong.
I have no idea what this means. how is it subordinate? The location on the filesystem?
"Look at any thick-client Rails project and count the number of gems managing javascript"
I've made a few that have no gems managing javascript. They talk to rails via REST. Rails doesn't need to care about them, and they don't need to care about rails.
If you can tell me how I can get 100% of my javascript assets managed by javascript code and still allow the use of rspec for end to end acceptance testing, I'm all ears. How do you get Rails, at one point of contact, to had off all asset recompilation, concatenation, minification, cache busting through md5 fingerprint hashing, etc. to javascript, I'm all ears.
I wanted to use require.js before. Spent a couple days working it into the project, but couldn't get it to work because of incompatibilities with sprockets. Undid everything. Someone made a require.js rails plugin, and I tried it again. It turned out to be incompatible with how the jasmine gem works and the jasmine gem is organized the way it is because that's how gems are supposed to be organized. Again, after wasting several days trying trying to get everything to work, I tore it all out again.
It's like whoever designed sprockets hasn't even considered the possibility that maybe it should permit javascript to be used freely with javascript within a Rails projects without intermediating. Near as I can tell, all the intermediation is done to be able to such things as maintaining all the files in the same directory organization (app, config, lib, vendor).
I'd split things down into something like this to cleanly separate the concerns of ruby and javascript: /client/ --/app/ --/config/ --/lib/ --/vendor/ --/spec/ /server/ --/app/ --/config/ --/lib/ --/vendor/ --/spec/ /shared/ --/stylesheets/ (if you render both static and dynamic. otherwise put this in the appropriate directory above) --/config/ --/spec/acceptance/
How do you keep all your ruby out of your javascript?
p.s. you don't have to use sprockets if it doesn't fit your needs. Your javascript can live outside of your rails app.
You can still do that, you can turn the asset pipeline off and just throw everything in /public like normal if you want.
Re: "through Ruby." If you meant that the body of the CSS file is generated for a request by running through the ruby interpreter, that's not true.
Any web framework has the duty to use and promote proper HTTP usage. Pushing PATCH over PUT we are doing that.
This change is not the entire Rails 4.0, it is only one change in Rails 4.0. Rails 4.0 has still a long way to go.
And of course, there are going to be practical improvements as there have been in all major (and indeed minor) versions. We will do practical improvements as well as being better HTTP citizens.
PATCH has the same idempotent requirement. It isn't simply some more generic version of PUT intended for generic CRUD updates. As I understand, it is a specific way to submit a "diff" of a resource to "patch" it so to speak.
PUT/PATCH verbs as far as HTTP/REST is concerned seem to have been designed with literal management of resource data/state in mind. The primary scenarios I can think of that require their use are things like blob storage APIs and perhaps other types of direct content management scenarios. It just doesn't seem appropriate as the general "update" mechanism that Rails is trying to make it out to be.
I'm not saying the Rails way of doing CRUD is bad. It's a handy abstraction and pattern that works fine for many, even most, cases, but as far s REST goes, Rails is really just RESTful theatre. From what I can tell the most RESTful thing Rails could do is just use POST by default everywhere and provide a convenient way for the developers to use PUT/PATCH where and when it truly makes sense.
Lots of people care. It's about following existing standards to allow for more predictable behavior. What if people didn't care about status code 200 vs 404?
And if you don't care... what's with the rant?
The PATCH method thing only becomes relevant in conjunction with APIs where I would hope that you have enough control over your environment to not having to deal with broken proxies.
On the upside, using PATCH instead of PUT, in the context as PUT is used most often these days (partial updates) is more compliant with HTTP which says that the body of a PUT request should contain the whole resource, not just parts that change.
In a good majority of API cases the correct method is POST, even for so-called updates. Because, generally speaking, it is the controller that decides what happens to state when processing the request in Rails and if and when there will be side effects. Unless you can be certain the client will decide 100% of the result of the state PUT and even PATCH are just not technically correct.
PATCH is arguably better suited than PUT here but again why the strict adherence to one or the other for updates, when quite possibly neither is correct. Why PATCH by default? Why not just POST by default, PATCH/PUT where they make sense? In the end there is nothing specifically RESTful about Rails, it has no real resources or hypermedia to speak of so I can understand why people would question the real value of this move.
Assume I'm stupid.
Explain to me, but don't stop at "because it's more compliant to the HTTP Standard" / "because thus it has been written in the scriptures" mustn't be the fundamental reason to do something.
Similarly, "it is Good to be compliant with the HTTP Standards in this case, because in other cases it was Good also"--certainly I can understand that being compliant with the 200 and 404 status code is a Good Thing.
But is there any other, tangible reason why a Rails project would benefit from now using PATCH instead of PUT? Some interoperability with another existing framework maybe? Or interoperability with a hypothetical future framework? What other kinds of software would need to be changed and used before it'll provide a tangible benefit to a Rails project that uses PATCH vs a Rails project using PUT?
BTW I'm not arguing against standards (I know, I said you may assume I'm stupid, but no need to go all out ok?), I'm just genuinely curious if there is any other benefit, real, future, hypothetical or imaginary, other than "it's more compliant, and being compliant is good".
Actually even if that is the only reason, that's nice, it makes things neater and that's also good. But it would be kind of thin.
PUT is A) idempotent (meaning that repeated operations have the same result), and B) always replaces the entire resource (and by implication should contain the entire new resource).
PATCH is A) not idempotent (meaning that repeated invocations could have different results), and B) affects part or all of the resource.
So, an immediately obvious benefit[1] is that PATCH requests are potentially much lighter-weight.
[1] Aside from conceptual clarity which I frankly cannot fathom reasons for arguing against, yet many do…
It seems like the post is intended to highlight a high quality commit which somebody worked hard on, as well as prepare the community for a semantic change. It may not be worth touting as much as a competitive feature, but it certainly deserves it's place in the feed.
But really, the only thing that bothers me with this post is the under-developed blog it's been running on for years (ie.: no simple way to get to archives, next or previous post, etc).
Advocating against PATCH is near to advocating against the introduction of RESTful routes and controllers, which was a crucial gain for Rails (even though they probably got the hint from Django?).
P.s.: Socket.io isn't part of Node.js core either. There are implementations in Ruby, but why not just use Node and Socket where appropriate?
I code with Rails. With Rails 3.2, I'm more productive than I've ever been. What others call "bloat", I call "features". It is surprisingly good having an out of the box asset pipeline for optimization of JS/CSS. The simplicity with which you can construct and adjust scoped queries with ActiveRecord is astounding. The ease of adding pre-baked authentication and authorization gems is great.
Seriously - screw writing a large data-driven web app in a tiny framework. You get so much for free in Rails.
Yes, Rails has some issues. It has a long initial load time. Ruby is not the fastest language. My main complaint about Rails at the moment would be that it moves too quickly - not that it moves too slow. If you're writing an app to service millions of users simultaneously (and not charging for it), the speed might be an issue. I haven't found it to be a problem in my company, where we charge money for what we write.
And on this change - I'm not fussed either way, but it's certainly good that Rails core mention this on the Rails blog so that Rails developers are aware of it well before 4.0 comes out. And standards compliance is a good enough reason for me.
If you want to make a drum machine that runs in your browser, like Giles Bowkett, then perhaps Ruby on Rails is really not good for you. On the other hand, if you want to earn a living, then the tremendous ease with which you can produce a reliable, secure, and full-featured application with Rails is really quite astounding.
I do think that some of the criticism around the thick-client support in Rails is justified, however. Rails was ahead of the pack when it came to AJAX support in the early days, but it is not leading the way when it comes to thick-client architecture. At the same time, however, when the core developers announced that Rails would default to Coffeescript, half of the developer community freaked out, including many people here on HN. At this point, there are so many people with a stake in Rails it is impossible to please them all.
I'm very happy with where rails is at right now. I feel incredibly productive with it. I get to play with new fancy stuff because I know it's still there to bail me out and get it done fast when I need to.
I find neither a suit nor skinny jeans comfortable. Instead rails fits like a well worn in pair of jeans and a plain old t-shirt. Sell the hipster crap somewhere else.
Also, it's standardizing the language that developers are using to interact with each other, and reducing the amount of work needed to build interoperable software. As more and more websites turn into web services (even if those services are only consumed by e.g. client-side Javascript), this should result in cost savings and faster time-to-market as more businesses move in that direction.
Finally, a lot of web apps are basically just CRUD (create/read/update/delete) apps. The more we standardize the on-the-wire protocols for these routine operations, the more we can push those protocols into application frameworks. This means that, as developers, we can work on things that are actually valuable, rather than coming up with new, site-specific ways of shuffling this data around the network.
Edit: I just noticed that RFC 2616 mandates write-through behavior: http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13...
https://github.com/rails/rails/issues/348
https://github.com/rails/rails/pull/431
Ideally you wouldn't need to do partial updates and just send the entire resource; your resources shouldn't be so big that that's an issue. It's much simpler than making the front-end decide when to do full versus partial updates and which method to use.
Rails can't really do that though, too much legacy code out there, too many people set in their ways. Resorting to PATCH is their only option if they want to use HTTP correctly.
I had actually thought to try to use a Rails-based REST service in the future, because I thought it would be quicker than rolling my own again (I had no choice, honest!) but without partial updates, I couldn't use it.
> "Rails to use PATCH instead of PUT" Http nerds annoy me
> "it's actually doing is un-breaking HTTP caching
> and proxying semantics" ... roll eyes
- ryah
https://twitter.com/ryah/status/173683063371464704In fact, I would argue that things like put/patch/_method are what make Rails so great. Rails makes a lot of strong opinions (put, whoops no, patch!), but then at then end of the day always gives you a way (_method) to deal with any issues where their opinions may not work in your current architecture. This pattern appears throughout the framework and is one of the reasons I really enjoy Rails.
Imagine if this was "we are using a new non-HTTP network protocol, and the answer to "how will you get it through proxies" is not "we tested it: it works" but instead "we have a way to tunnel it over HTTP"... that is a non-answer that undermines the entire purpose of having a new protocol, and restating it with pointlessly denegrating statements about people who don't know about the tunneling system doesn't help: it just makes the feature that much more questionable. :(
Look the counterfactual: any protocol (including HTTP...or TCP...or IP...) has "no advantages" unless both endpoints can understand it and the network can transmit it at the most appropriate layer. Until then, it requires tunnelling. That was definitely the case for the first rollout of TCP/IP, or HTTP.
It definitely doesn't imply that it shouldn't be done--the only thing that it implies is that it's harder work for the adopters until it has a critical mass of mind share and then it becomes harder for the non-adopters. If the alternative to that is no, or only centralized, improvements to protocols, I'll take the breakages.
The saddest part here is that I agree with you: I like that Rails decided to do this, and for the very reasons you describe. However, I expressed disappointment that this announcement/article decided to ask "will my web server support this" and didn't bother to ask "will the client be able to route to me with this".
Remember: I myself believed it would work, and even provided multiple reasons in my post for why it would. However, it would have been nice to see these points brought up in the article. If my version of nginx doesn't support it, I'll just upgrade, but if I'm honestly concerned about support, I'm going to care if I can even trust a PATCH to my client code.
What's the complaint here? Rails can't do anything about shitty proxy software. It's there, and Rails works around it.
My "complaint" (I am not certain why you are using that term, as all I said was that I had a "disappointment" with the article announcing the feature) is that time was spent discussing "does my web server support it" (you can always change your webserver) as opposed to "will my client support it" (which is an interesting and important question).
(Also, it should be noted that Rails doesn't work around the "shitty proxy software": it provides a way to allow the client code to work around it, but it doesn't itself work around it. If there really are networks out there that don't route PATCH--which I didn't even believe in my original post, but was corrected with this K-12 failure--then you, the developer, are going to end up just never using PATCH.)
I think what you're saying though is that the downsides are. You may be right on that, but I'm going to withhold judgement until I really figure out what this means.
The way I've understand it is that GET is for reads (which are always idempotent), PUT is an idempotent write and POST is a non-idempotent write. I don't see what PATCH adds over POST.
(commented this on the article as well)
Playing with rails for more than 3 years, and then suddenly something new comes and hits you is obviously going to hurt. Let me start with the Assets Pipeline, and in particular - style & script.
Did you feel that it is important to control the no. of bits and bytes going into your css now? Until Sprockets came by, people would drop a load of crap in the public/stylesheets (bloated with properties !importants and all).
Continuing this way, is going to affect your app's responsiveness on new landscapes - aka tablets, hand-helds especially if you're thinking about "app-development with non-native approach" in your mind.
I mean it's not about syntactic sugar alone. It's about the ability to see what can be removed completely from the code and dried up to give desired result with maximum re-usability.
Now I'd credit this to the "direction of rails" which served SASS/SCSS or coffeescript as default. It forced me to think and add programming logic into style. Personally, I like it.
Also what fails me, is the classic nodejs vs Rails war. Let me re-word this: It is a classic unfounded flame-war, as described in HN guidelines. Both technologies have a place and are useful for even more mutually-exclusive scenarios. Why compare?, just do you own thing!
To sum it up - there is a need to take a step back and consider the idea "you wouldn't bump on something new thing or useful with status quo." I would definitely like to consider PATCH over PUT.