How to use DELETE http method while deleting resources in Restful web service ?

I have read that we need to use DELETE http method while deleting resources in Restful Environment.
Till now I have managed to delete resources using  GET.
How do I use DELETE http method for deleting resources ?
I have tried following.
<form action="../de.pradip.jersey.todo/rest/todos" method="DELETE">	

Open in new window


Follow this site for more details : http://www.vogella.com/tutorials/REST/article.html
Pradip ShenolkarAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mccarlIT Business Systems Analyst / Software DeveloperCommented:
Firstly, no, "form" methods only support GET and POST, so you can't do delete like that. You can submit "DELETE" request via Ajax though. But how all that can work with what you are doing, we can't really say with the little amount of information that you've provided.

If you want further help, you will need to tell us more about what you are doing, such as what frameworks/libraries you are using on the client side (jQuery, etc) and what you are using on the server side (Spring, etc)? And any other detail that could be useful for us to help you out.
0
Shalom CarmelCTOCommented:
If you consume the web service from a browser, then AJAX is necessary. Here is some example javascript code:
function execute($method,$url){ 
   xhr=new XMLHttpRequest(); 
   xhr.onreadystatechange = function() {
      if (xhr.readyState == 4) {
          return(xhr.responseText);
      }
   }
   xhr.open($method,$url,false) 
   xhr.send(null); 
   return(xhr.responseText);
} 

execute('DELETE','http://someurl..");

Open in new window


And here is an example using the command line curl tool
curl -X DELETE "http://someurl.."

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Pradip ShenolkarAuthor Commented:
Hi shalomc

What I want exactly is, there is one simple application at following url.
But it allows only creating new resources. I want to implement deletion of resources in same application.
Could you please go through the link and help me achieving it ?

Go to point number 9.1 Project at below link. Skip point 9.5 because I am using html form to send request.

http://www.vogella.com/tutorials/REST/article.html
0
OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

mccarlIT Business Systems Analyst / Software DeveloperCommented:
But it allows only creating new resources. I want to implement deletion of resources in same application.
That's not correct, it does allow for deletion of resources. Check out point 9.3, the code for the class TodoResource contains a method towards the bottom called deleteTodo that accepts the DELETE method.

Skip point 9.5 because I am using html form to send request.
If you will read again the previous comments that we both have made, you will see that we both said that submitting a delete request via HTML forms is not possible. You need to use ajax methods to do that as in the example given by shalomc.
0
Pradip ShenolkarAuthor Commented:
Hi mccarl
You are absolutely right.
Since I am new to Restful web services, I don't  know how to use the code provided by shalomc in that application to get it work.
0
Shalom CarmelCTOCommented:
The example web service supports the DELETE method, see 9.3 point.
However, you cannot use DELETE directly from html form.
You will have to verify that DELETE works by using one of the methods I mentioned, or by any other client that supports DELETE. I suggest that you get acquainted with curl as a command line tool, as it is the best tool to debug and test everything http related, including web services.

This should work and delete todo #1.

curl -X DELETE http://localhost:8080/de.vogella.jersey.todo/rest/todos/1

or this in browser javascript will also delete todo #1
<script>
function execute($method,$url){ 
   xhr=new XMLHttpRequest(); 
   xhr.onreadystatechange = function() {
      if (xhr.readyState == 4) {
          return(xhr.responseText);
      }
   }
   xhr.open($method,$url,false) 
   xhr.send(null); 
   return(xhr.responseText);
} 

execute('DELETE','http://localhost:8080/de.vogella.jersey.todo/rest/todos/1");
</script>

Open in new window

0
Pradip ShenolkarAuthor Commented:
@shalomc
I will try this.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Services

From novice to tech pro — start learning today.