none
Difference between the REST verbs PUT and POST

    Question

  • Hi,

    Could anybody provide me an example which will show the differences between the REST verbs PUT,POST and DELETE using WCF REST services? I have read that PUT/DELETE performs a action once even though two requests are sent, whereas in the same situation POST executes twice. Also, there are other differences. I want to explore the differences using WCF REST services. If any body provide an example of WCF REST services, which shows the differences between those verbs, that will be very helpfull for me.

    Regards

    ronit_rc



    • Edited by ronit_rc Sunday, May 06, 2012 7:21 AM
    Sunday, May 06, 2012 7:04 AM

All replies

  • Hi, why read about it when you can watch it. This video may give you a better understanding:

    http://channel9.msdn.com/shows/Endpoint/endpointtv-Screencast-Consuming-REST-services-with-HttpClient/

    Sunday, May 06, 2012 10:28 AM
  • Hi ,

    Thanks for the answer. Actually, I am quite aware about REST concepts. I have also implements 4 REST verbs using WCF service. What I am looking for, that would be an implementaion example using WCF REST, which expliains the difference between PUT,POST and DELETE verbs.

    Thanks in advance.

    Regards

    ronit_rc 

    Sunday, May 06, 2012 5:21 PM
  • Hi, these Service Station articles are my favorites and may deliver what you need:

    http://msdn.microsoft.com/en-us/magazine/dd315413.aspx

    http://msdn.microsoft.com/en-us/magazine/ee309509.aspx

    Sunday, May 06, 2012 9:51 PM
  • Hi,

    Thanks for your help. These articles are really good but doesn't anser my query.  I want an example which explains the differenciation between the REST verbs PUT and POST and DELETE using WCF REST. If anybody from Microsoft community can come out with an example, that will be very helpfull for me.

    Thanks in advance.

    Regards

    ronit_rc

    Monday, May 07, 2012 4:54 AM
  • Hi, this link may provide the deeper understanding you are after:

    http://jcalcote.wordpress.com/2008/10/16/put-or-post-the-rest-of-the-story/

    Monday, May 07, 2012 2:53 PM
  • Hi,

    Thanks again.

    This is the post where from I came to know there are differences between PUT and POST. Like, on sending a request in two quick succession PUT verb is allways execute a method once while POST verb twice. I am looking for an example which implements and shows this kind differences using WCF REST service. I am not getting any example in net, if anybody from the community can implement and show this kind of example,that will be very helpful for me.

    Thanks in advance.

    Regards

    ronit_rc


    • Edited by ronit_rc Monday, May 07, 2012 5:24 PM
    Monday, May 07, 2012 5:23 PM
  • Hi ,

    Thanks!

    Everybody is providing several links regarding REST. Those posts might have explained REST service and theoritically the differences between PUT and POST. But, none of them site an example which has  implemented the differences between PUT and POST in WCF REST or any .NET application.

    It would be very helpfull if anbody implement the same using WCF REST.

    Regards

    ronit_rc

    Thursday, May 10, 2012 10:20 AM
  • Hi,

    I have tried to implement a REST WCF in order to explore difference between PUT and POST verb.  I have uploded a file in a location using the service.

    The service implementation is as folowing:

    OperationContract]
    [WebInvoke(UriTemplate = "/UploadFile", Method = "POST")]
    void UploadFile(Stream fileContents);

    public void UploadFile(Stream fileContents)
    {
         byte[] buffer = new byte[32768];
         MemoryStream ms = new MemoryStream();
         int bytesRead, totalBytesRead = 0;
         do
         {
               bytesRead = fileContents.Read(buffer, 0, buffer.Length);
               totalBytesRead += bytesRead;

               ms.Write(buffer, 0, bytesRead);
          } while (bytesRead > 0);

          using (FileStream fs = File.OpenWrite(@"C:\temp\test.txt"))
          {
              ms.WriteTo(fs);
           }
             
          ms.Close();
     }

    Client code is as following:

    HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://localhost:1922/EMPRESTService.svc/UploadFile");
                request.Method = "POST";
                request.ContentType = "text/plain";

                byte[] fileToSend = File.ReadAllBytes(@"C:\TEMP\log.txt");  // txtFileName contains the name of the file to upload.
                request.ContentLength = fileToSend.Length;

                using (Stream requestStream = request.GetRequestStream())
                {
                    // Send the file as body request.
                    requestStream.Write(fileToSend, 0, fileToSend.Length);
                    //requestStream.Close();
                }

                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                    Console.WriteLine("HTTP/{0} {1} {2}", response.ProtocolVersion, (int)response.StatusCode, response.StatusDescription);
                Console.ReadLine();

     The file is being uploaded and the response status code is being returned as "200 OK".  The satus code is same in case of existance or non-existance of the file in the upload location.

    I have changed the REST verb to PUT and the status code is same as above.

    Could anybody explain, how I can identify the differences between the verbs in this context? I couldn't able to simulate geneating continious request fron client code. If the behaviour will differ on doing so, could anybody help me in modifying the client code in oredr to send continious request in a row ? 

    Thanks in advance.

    Regards

    ronit_rc

    Friday, May 11, 2012 8:55 AM