cURL: DELETE request examples
DELETE request examples with my most frequently used command-line options.
The examples for
DELETE are very similar to those detailed in my post explaining how to do GET requests in cURL or the one about PUT requests.
The most basic command you can execute with cURL is an HTTP
DELETE request without a payload.
To tell cURL to use a DELETE request method we can use the
--request command-line option, the following command will perform the request using the
DELETE verb and output the response body:
curl -X DELETE https://blog.marcnuri.com
DELETE request with data
Sending a payload body with a DELETE request is something discouraged and not recommended.
The only reason we didn't forbid sending a body is because that would lead to lazy implementations assuming no body would be sent.
However, it's not strictly forbidden in RFC 7231, and you might be in the need to test it from a client perspective.
A payload within a DELETE request message has no defined semantics; sending a payload body on a DELETE request might cause some existing implementations to reject the request.
If despite the warning, you need to send some data in the payload of the DELETE request, you can use the
--data command-line option. When using the data option, cURL sends data just like your browser would when you fill an HTML form and press the submit button. In addition, cURL will automatically add the
Content-Type header with an
curl -X DELETE -d "field=value&tool=curl" https://postman-echo.com/delete
These are some of the common cURL
DELETE HTTP request examples I use on a daily basis. I hope they may come in useful for you too.