Send a curl DELETE Request {With Example}

Introduction

Curl is a command line tool used to transfer data to and from a server. It is a versatile tool that can be used to make a variety of requests, including DELETE requests. A DELETE request is used to delete a resource from a server. In this tutorial, we will discuss how to send a curl DELETE request with an example. We will also discuss the syntax of the curl command and the various options that can be used with it.

Send a curl DELETE Request {With Example}

curl -X DELETE http://www.example.com/api/v1/users/123

Introduction

cURL (client URL) is a command-line utility for transferring data to and from a server. The tool allows communication with a web or application server and sending method requests directly from the terminal.

The HTTP DELETE method request sends a signal to the originating server to delete a resource.

This tutorial explains how to send a curl DELETE request through an example REST API JSON server.

Send a DELETE Request Using curl

Prerequisites

  • Access to the command line/terminal with administrator user privileges.
  • NodeJS and NPM installed and updated.
  • Access to a text editor.

Note: To install NodeJS and NPM, follow our OS-based guides for:

Curl DELETE Request Syntax

The basic syntax to send a DELETE request method using curl is:

curl --request "DELETE" <URL>

Alternatively, use the shorthand version:

curl -X "DELETE" <URL>

The curl command sends a DELETE request to the HTTP server, deleting the page or entry at the provided URL.

Curl DELETE Request Example

The example below demonstrates how the curl DELETE request works. The example creates a fake REST API server using the JSON server package.

1. Open the terminal (CTRL+ALT+T).

2. Run the following command to install the json-server library using the NPM package manager:

sudo npm install -g json-server

3. Open a text editor and create a database.json file. If you’re using nano, run:

nano database.json

4. Add the following data:

{
  "people": [
    {
      "id": 1,
      "name": "Matthew"
    },
    {
      "id": 2,
      "name": "Mark"
    },
    {
      "id": 3,
      "name": "Luke"
    }
  ]
}

The file represents a mock database of people with unique IDs and names.

5. Save the file and close the text editor.

6. Run the following command to start the server:

json-server --watch database.json
json-server --watch database.json terminal output

The server starts locally, listing the following two pages:

  • Resources at http://localhost:3000/people contains the data defined in the database.json file.
json database on localhost browser page
  • Home at http://localhost:3000 contains the landing page with the message that the server is up.
json server running

7. In a new terminal tab, send a DELETE request using curl:

curl -X "DELETE" 'http://localhost:3000/people/3'
curl delete request terminal

The terminal outputs an empty set. Check http://localhost:3000/people to confirm the third entry is no longer there.

json database deleted entry

The server session in the command line/terminal shows the DELETE request with a server response of 200 (success).

json server curl delete request response 200

Attempting to delete non-existing data results in a server response 404 (not found).

Conclusion

After following the steps from this tutorial, you understand how to send a DELETE request through the command line using the curl command.

Next, see how you can change the user agent with curl.

Send a cURL DELETE Request: With Example

cURL is a command-line tool used to transfer data to and from a server. It supports a wide range of protocols, including HTTP, HTTPS, FTP, and more. One of the most useful features of cURL is its ability to send DELETE requests. This article will explain how to send a cURL DELETE request with an example.

What is a cURL DELETE Request?

A cURL DELETE request is a type of HTTP request that is used to delete a resource from a server. It is similar to a GET request, except that it sends a DELETE command instead of a GET command. The DELETE command tells the server to delete the specified resource.

How to Send a cURL DELETE Request

Sending a cURL DELETE request is relatively simple. All you need to do is specify the URL of the resource you want to delete, and then use the -X DELETE option. Here is an example of how to send a cURL DELETE request:

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

This command will send a DELETE request to the specified URL. If the request is successful, the resource will be deleted from the server.

Conclusion

In this article, we have explained how to send a cURL DELETE request. We have also provided an example of how to use the -X DELETE option to send a DELETE request. cURL is a powerful tool that can be used to transfer data to and from a server. With cURL, you can easily send DELETE requests to delete resources from a server.

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

Contact
San Vito Al Tagliamento 33078
Pordenone Italy
Item added to cart.
0 items - 0.00
Open chat
Scan the code
Hello 👋
Can we help you?