File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Services and the fly likes doubt regarding deleting a resource in REST WS with or without DELETE method? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "doubt regarding deleting a resource in REST WS with or without DELETE method?" Watch "doubt regarding deleting a resource in REST WS with or without DELETE method?" New topic
Author

doubt regarding deleting a resource in REST WS with or without DELETE method?

Satyaprakash Joshii
Ranch Hand

Joined: Jun 18, 2012
Posts: 131
I have a doubt regardiing DELETE In Restful Web services....Suppose we are deleting a Resource using the Id, DELETE is the method for this ...but the same task can be performed with GET or POST by just passing the ID...and deleting that from the database....if so then what is the difference between these two apporaches..

Thanks...
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12781
    
    5
The point is that by using the DELETE HTTP method, you are maintaining architectural clarity.

Yes, you will see non-RESTful use of HTTP methods, especially GET and POST used for all possible functions all the time.

Elegant style versus sloppy style - - I think I will go with elegant.

Bill

Satyaprakash Joshii
Ranch Hand

Joined: Jun 18, 2012
Posts: 131
Thanks Bill for the clarification..Yes one is the elegant style and the other is the less Restful use of web service as you have clarified

..but using the second one..one advantage we are getting. .--->we dont need to have or database design in sync with the web service XMLs....because using the get or post we are just passing the unique id and then we have the flexibility of doing whatever we want on the server side..with the database ...Is it now so?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12781
    
    5
Satyaprakash Joshii wrote:
..but using the second one..one advantage we are getting. .--->we dont need to have or database design in sync with the web service XMLs....because using the get or post we are just passing the unique id and then we have the flexibility of doing whatever we want on the server side..with the database ...Is it now so?


Sorry, that does not make any sense to me. What does database design have to do with it?

Bill
Satyaprakash Joshii
Ranch Hand

Joined: Jun 18, 2012
Posts: 131
Here is the scenario and my doubt..I have Contacts POJO which has Customer Id ,Customer name,Customer contact info...I am using DELETE method as r.path(id).delete(ClientResponse.class); to delete the Contact...
After this step, the Contact with the paticular Id is already deleted and the resource no longer exists. Its done...But did I delete the contact from the database? No......So it still exists in the DB....So what is the significance of deleting it from the database as operation is already performed without deletion form the DB?

thanks..
Satyaprakash Joshii
Ranch Hand

Joined: Jun 18, 2012
Posts: 131
I got my answer for what is the difference.....If I am using DELETE method without deleting from DB...The resource is deleted..but since it is stateless thing, once we restart the server it still exists....
Satyaprakash Joshii
Ranch Hand

Joined: Jun 18, 2012
Posts: 131
If I use DELETE method of REST WS..., the resource will be deleted but since it is stateless suppose server is restarted the record will still be there...So will have to go with GET or POST method in this case pass the customer Id and delete the record from the database...My doubt is that what would be the examples where DELETE method will server the purpose...Can you tell any example when deleting using DELETE method will be useful?(because in my case on restarting the server deleted record will still show due to statelessness)....

thanks..
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12781
    
    5
the resource will be deleted but since it is stateless suppose server is restarted the record will still be there...


What in the world are you talking about? Are you thinking there is a magic DELETE method hidden somewhere? NO!

It is up to you to write your own DELETE method so if your DELETE method actually deletes the record from the database it will be gone gone gone.

Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: doubt regarding deleting a resource in REST WS with or without DELETE method?