users@jersey.java.net

DELETE Response status code...

From: Rabick, Mark A (IS) <"Rabick,>
Date: Thu, 30 Apr 2009 10:33:25 -0500

What is the best choice for an HTTP response status code for the successful deletion of a 'resource'? I have a DELETE method:

        @DELETE @Path("{sk: [a-zA-Z0-9 ]{1,32}}")
        public synchronized Response deleteNodeBySk(@PathParam("nodesk") String nodeSk) {

                Response resp = null;
                
                Node nodeToDelete = new Node(nodeSk);
                nodeRemote.delete(nodeToDelete);
                /*
                 * Response Status code is 204 (No Content)
                 */
                resp = Response.noContent().entity(null).build();
                System.out.println("Deleted sk: " + nodeSk);
                
                return resp;
        }

I've looked at the examples and mostly see delete methods returning 'void'. The method is synchronous above so the delete should be complete before the method returns. Is the 204 (No Content) appropriate or would a 205 (reset content) or 200 (ok)?

I've seen a couple of different examples for each on 'the net'.

The other question I have is on a 'create' method (@POST). I want to return both the URI for the newly created entity as well as return the created entity itself in the message body. Would the URL go in the Location header? If so, how is that accomplished?

--mark

_______________________________________________
Mark A. Rabick
Software Engineer
Northrop Grumman - Integrated Mission Systems (IS/DSD/IMS)
3200 Samson Way
Bellevue, NE 68123
Ph: (402) 293-7091
Em: mark.rabick_at_ngc.com
Remember PFC Ross A. McGinnis...
  http://www.army.mil/medalofhonor/McGinnis/index.html
... MA2 Michael A. Monsoor, Lt. Michael P. Murphy, Cpl. Jason Dunham, SFC Paul Ray Smith and the rest...
  http://www.cmohs.org/recipients/most_recent.htm