On RESTful API Standards – Just Be Cool: 11 Rules for Practical API Development
techblog.appnexus.com
techblog.appnexus.com
"The model application is therefore an engine that moves from one state to the next by examining and choosing from among the alternative state transitions in the current set of representations."
http://weblogs.java.net/blog/mkarg/archive/2010/02/14/what-h...
"But honestly, why would your users be creating an object with an id?" They aren't. You should not be PUTting endpoints with an id. I get more more and more scared as I type, thinking about this change-the-standard-for-my-own-purpose attitude.
There are about a million questions you must ask yourself in order to come to the right answer for YOU. At the end of the day what matters is that the person using your API finds it easy and intuitive. If that means that you use PUT for updates, and POST for creation, so be it. It could even mean that you convert PUT to POST requests, and treat them all the same. If you take that route, you check to see if the resource ID is specified in the post data. If the ID is in there, you update that resource, if it's not in there you create a new resource.
While you go forward, keep in mind one thing. If your API is hard to use then no one will use it. If no one uses it, then your API doesn't matter. If your API doesn't matter, then you made all the wrong decisions.
Also, have fun with it. Creating APIs is incredibly fun, enjoy yourself, and enjoy creating something people will enjoy using.
Replacing the nonsense of SOAP and XML-RPC with equally ridiculous pedantry about HTTP minutiae is not helping your cause nor your software.
edit: Well, ajross has a point. There are actually all of eight HTTP 1.1 methods, and PATCH is not one of them.
It is "easy" to blindly follow any rule. In most cases it is also wrong.
> It is "easy" to blindly follow any rule. In most cases it is also wrong.
Come on.
Feeling entitled to making firm pronouncements about "correct" behavior on subjects one is not an expert in (and let's be clear: no one is an expert on PATCH yet) is in some sense the very definition of "cargo cult mentality".
Edit: that's probably harsher than it's intended. My point isn't really about PATCH, which seems sane. It's about the pedantic mentality which is running rampant in the REST community (c.f. the "ARGH!" above), which in my mind is taking a good idea and polluting it with terrible nonsense in the pursuit of "purity". Think of what happened to Agile if you continue down this path.
Rack::MethodOverride does this for Rack-based apps by using the value of the _method parameter as the http verb.
Having said that, I like subresource URLs and using PUT to do partial updates like that.
1. 400 bad data - a failed request
2. Blank out / delete the values of all fields not specified
3. Perform a PATCH-style partial update
Which of these is the most useful / least surprising / closest to the spec?
Now read the spec: http://tools.ietf.org/html/rfc2616#section-9.6 PUT should store the request as the resource, it doesn't have to. Also note the complete absence of push from the precious specification! (I know patch is an amendment, my point us that the HTTP spec shouldn't be considered perfect)
If PUT falls back to PATCH, then there's no replace action, which might be useful.
It doesn't end up being a huge deal practically, because partial updates are probably more common than replaces, but that's my reasoning for it.
I'm doing this for the API I'm building, as modeled on FatSecret's API.