tags:

views:

170

answers:

1

I am new to web services. I am dealing with testing APIs in my project. In the previous version the company used GET and POST methods but not PUT and DELETE methods. I need help for the HTTP DELETE method. I have browsed various websites where I found the example code snippets for GET and POST methods, but not for DELETE and PUT methods (why?).

Can anyone give me an example code snippet (C#) for RESTful HTTP DELETE method and explain how to call the DELETE request?

+1  A: 

Chek out the following code snippet:

string sURL = "<HERE GOES YOUR URL>";

WebRequest request = WebRequest.Create(sURL);
request.Method = "DELETE";

HttpWebResponse response = (HttpWebResponse)request.GetResponse();

In the response object you should check the StatusCode property (it should be 200 or 204 if everything goes right, see here for more info).

Anero
Thank you.But I have one question here.In my case I need to remove a container which has a specific ID (container_ID). So to delete this specific container is it enough to give the URL as follows"http://www.viba.com/api/picsharing/rest/container/container_id"and with this URL will the DELETE call removes all the elements related to that specific container"
VIBA
It's enough to reference the resource (in your case, the container) with the URL but you must validate the HTTP verb.Also, delete operation should be Safe and Idempotent (check this for more info: http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html)
Anero