How to Send an HTTP DELETE Request with Curl

This guide provides a straightforward explanation of how to execute an HTTP DELETE request using the curl command-line tool. You will learn the basic command syntax, how to pass custom headers, and how to include a request body when interacting with RESTful APIs.

The Basic DELETE Request

To send a standard HTTP DELETE request, use the -X (or --request) option followed by the DELETE method and the URL of the resource you want to delete.

curl -X DELETE https://api.example.com/resources/123

Sending Headers with a DELETE Request

Many APIs require authentication or specific content types to process a deletion. You can add headers to your request using the -H (or --header) option.

For example, to send a request with an authorization token:

curl -X DELETE -H "Authorization: Bearer YOUR_API_TOKEN" https://api.example.com/resources/123

Sending a JSON Payload (Request Body)

While not standard for all APIs, some endpoints require you to send data in the body of a DELETE request. You can pass data using the -d (or --data) option and set the Content-Type header to application/json.

curl -X DELETE \
     -H "Content-Type: application/json" \
     -d '{"reason": "no longer needed"}' \
     https://api.example.com/resources/123

Viewing Response Headers

To inspect the HTTP response headers (such as 204 No Content or 200 OK) returned by the server, add the -i flag to your command:

curl -i -X DELETE https://api.example.com/resources/123