Curl Part 3: using the DELETE method

In this article, we will continue discussing curl and how to use the DELETE method, an HTTP DELETE request to a server to remove data. Here…

Curl Part 3: using the DELETE method
Photo by Drew Farwell on Unsplash

In this article, we will continue discussing curl and how to use the DELETE method, an HTTP DELETE request to a server to remove data. Here are a few examples of how to use the curl command with the DELETE method:

Simple DELETE request

To make a simple DELETE request to a server, you can use the following syntax:

$ curl -X DELETE http://example.com/resource

This will send a DELETE request to the specified URL, asking the server to delete the specified resource.

DELETE request with headers

You can include additional headers in your DELETE request by using the -H option

For example:

$ curl -X DELETE -H "Authorization: Bearer TOKEN" http://example.com/resource

This will send a DELETE request with an “Authorization” header containing an access token.

DELETE request with query parameters

To include query parameters in your DELETE request, you can use the -G option and specify the parameters using the --data option.

For example:

$ curl -X DELETE -G --data "param1=value1&param2=value2" http://example.com/resource

This will send a DELETE request with the specified query parameters included in the URL.

DELETE request with a body

Some servers may require a request body to be included with a DELETE request. You can use the -d option to include a request body

For example:

$ curl -X DELETE -d '{"key":"value"}' http://example.com/resource

This will send a DELETE request with the specified JSON data in the request body.

These are just a few examples of using the curl command with the DELETE method. In our next article, we will discuss the PUT and PATCH methods that allow us to update data on a server.

Join Medium with my referral link - Konstantinos Patronas
As a Medium member, a portion of your membership fee goes to writers you read, and you get full access to every story…