Wednesday, April 10, 2013

PUT is idempotent which POST is not.

I saw Ryan Vice speak on ASP.NET Web API at Monday night Austin .NET User Group. I would say that this API is next on my list of things to learn but that may all change depending upon where I go work next. An example of a Web API method:

public void Put(int id, [FromBody]string value)
{
   
//whatever
}

[FromBody] above allows for binding against more than just stuff passed at the URL line. Think of JSON pushed in the body or header of a request. You may hand an object easily to POST and PUT. Mitch Fincher asked what the difference between the two was and Ryan explained that PUT is idempotent which POST is not. If you repeat an idempotent action act the repeat should cause no effect. You should be only causing an effect on the first push. Example: If you quadruple-click that button which is wired up to a PUT push-out you will not shove four identical records into the database. Ryan said that there is a "Client API" which will show you how to use the PUT method from the C# side. This is something for me to Google.

 
 

The opening act for Ryan was my employer of over five years, Dustin Wells, who sure seems like he knows what he's doing and especially so given some of the craziness I've witnessed during the past two years of not working for him. Dustin mentioned that he bought the pizza and that Headspring, his shop which you may have heard of, is hiring. I had some of his pizza and it was pretty good. That isn't really a surprise. He has the Midas touch. :P

No comments:

Post a Comment