Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Use HTTP DELETE Method

    Pete JohansonPete Johanson

    The HTTP DELETE method is used to request that the server perform a delete operation on the specified resource with resource specific semantics. Behind the scenes, the delete operation may result in a removal of a file from the filesystem, or an update to the database to reflect the change. Because multiple requests to delete the same resource has the same effect as a single one, the DELETE method is considered ‘idempotent’, but not considered safe.



    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson




    The HTTP DELETE method is used to perform a delete operation on the requested resource. I'm going to perform a delete. I have gist that I have starred as my user.

    Here, we can see that the DELETE method has been specified in the first line of my request. The server has responded with a 204 No Content response indicating success of my delete request.

    In addition to using 204 No Content without a response body, servers might also respond with 200 OK and include a message body with some more details about the successful request. Alternately, a 202 Accepted response may be returned. If the request to delete the resource has been accepted but not yet completed, it may take some time to perform that operation.

    It's important to note that the delete request relates to the resource identified by the URL. In the case of the GitHub API, the delete operation is performing some database update behind the scenes. To remove the fact that my user has starred this particular gist, other implementations may use delete on a particular resource to actually perform a file system delete behind the scenes.

    The HTTP DELETE method does not specify specifically the semantics of what is behind the scenes, merely the intended effect on the URL. It's important to note that the delete operation is item potent. I can resubmit this delete request and it will have the same intended effect.

    This allows both clients and browsers to resubmit a request if there is an error such as a network error during the processing of that request because the intended effect, deleting the given resource, is the same whether the request happens once or multiple times. You can see that even though I had already deleted the star in this gist, the server still returned me a 204 No Content response in response to my delete request.

    This may seem a little counterintuitive since a GET request on that same URL will return a 404 Not Found. This is because a delete on a resource that isn't necessarily there can still be considered success.

    To summarize, the HTTP DELETE method is used to perform a delete operation on a resource with unspecified semantics, meaning it might perform a file system delete or a database update in response to the request.