TechvBlogs
Published in

TechvBlogs

How to send a DELETE request with cURL

Jun 21, 2022, Originally published at techvblogs.com ・2 min read

What is cURL?

Curl is a command-line utility that allows users to create network requests. Curl is accessible on Windows, Linux, and Mac, making it the go-to choice for developers across all platforms.

A cURL is computer software and command-line tool used to make requests for different protocols. But the most popular usage with the curl command is making HTTP delete requests. Even the curl command-line tool is created for the Linux operating systems it is cross-platform and can be used for Windows, MacOSX, BSD, etc. In this tutorial, we will learn how to make different HTTP DELETE requests by using curl.

In this article, we’re going to explain how to use cURL to make DELETE requests. The HTTP DELETE method is used to delete data from the remote server.

HTTP DELETE request

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 -X, --request command-line option, the following command will perform the request using the DELETE verb and output the response body:

curl -X DELETE https://example.com

The -X flag specifies a custom request method to use when communicating with the HTTP server. By default, the GET method is used unless some other method is specified.

HTTP 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 -d, --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 application/x-www-form-urlencoded value.

curl -X DELETE -d "field=value&tool=curl" https://example.com/delete

Thank you for reading this article.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store