Send a curl DELETE Request {With Example}


The curl Delete task is an HTTP strategy that permits the evacuation of an indicated asset from a server. It is commonly used to Delete information or substances from a web service or API. The Delete request requires the URL of the asset to be Deleted, and extra headers or parameters can be included if required. When the server gets the Delete ask, it forms the ask and Deletes the desired asset in the event that it exists. An effective Delete request ordinarily comes about in an HTTP status code demonstrating the fruitful cancellation of the asset. Curl, a command-line instrument, is used to send the Delete request and handle the server's reaction.

Methods Used

  • Delete request method

Delete Request Method

Within the context of submitting a curl Delete ask, the Delete ask strategy is an HTTP procedure utilised to evacuate a specified server resource. It could be a significant component of the Serene plan and is habitually utilised in web administrations and APIs. The URL of the asset to be evacuated is included within the Delete request. The request is prepared by the server once it gets it, and on the off chance that the requested asset as of now exists, it is Deleted. At that point, the server answers with an HTTP status code demonstrating whether the Delete activity was effective or unsuccessful. The Delete Ask method, which empowers the cancellation of futile or out-of-date assets, keeping up information astuteness, and moving forward server proficiency, is basic for overseeing information and substances.

Syntax

curl --request "DELETE" <URL>

Algorithm

  • To perform a Curl-Delete-ask with the JSON server, follow these steps 

  • Install the JSON server bundle using npm or any bundle supervisor of your choice. Open your terminal or command prompt and run the following command 

Copy Code

npm install -g json-server
  • This command will download and introduce the JSON server universally on your system.

  • Create a JSON record that contains test information for the REST API endpoints. The JSON record ought to incorporate the assets and their comparing information, which they merely want to manipulate or Delete. For illustration, you'll be able to make a record named db.json and populate it with the required data.

  • Start the JSON server, utilising the JSON record as the information source. In your terminal or command prompt, explore the catalogue where the db.json record is found. Run the following command −

  • Css code 

json-server --observe db.json
  • This command will begin the JSON server and stack the information from the db.json file.

  • Open another terminal or command incite window and execute the Curl Delete Ask." Set the ask URL to the particular resource or asset you want to Delete. For example, if you need to Delete a particular client with an ID of 1, you'll utilise the following command:

bash
curl-X Delete http://localhost:3000/users/1
  • Make it beyond any doubt to supplant the URL (http://localhost:3000/users/1) with the suitable endpoint for your JSON server.

  • If required, include any fundamental headers or parameters in the Curl command. In this case, you'll be able to incorporate a confirmation token or indicate extra ask options.

  • Execute the Curl command by running it in your terminal or command incite. This will send the Delete request to the JSON server.

  • The JSON server gets the DELETE request, forms it, and Deletes the required resource on the off chance that it exists in the database.

  • The server reacts with an HTTP status code indicating the victory or disappointment of the Delete operation. An effective erasure is ordinarily shown by an HTTP status code of 200.

  • To confirm the successful cancellation, check the reaction code returned by the server. You'll also assess the server logs or recheck the information to guarantee that the required resource has been evacuated.

Example

{
   "people": [
      {
         "id": 1,
         "name": "Rati"
      },
      {
         "id": 2,
         "name": "Kushagra"
      },
      {
         "id": 3,
         "name": "Nandini"
      }
   ]
}

Output

Rati@:-$ json-server-watch database.json

\(^_^)/ ht!

Loading database.json

Done

Resources

http://localhost:3000/people

Home

http://localhost:3000

Type s + enter at any time to create a snapshot of the database Watching...

The server is successfully executed

The server session within the command line/terminal appears the Delete ask with a server reaction of 200 (success).

Rati@:~$ json-server-watch database.json

\(^_^)/ ht!

Loading database.json Done

Resources

http://localhost:3000/people

Home

http://localhost:3000

Type s + enter at any time to create a snapshot of the database Watching...

GET /people 200 6.357 ms - 128

DELETE /people/3 200 8.212 ms 2 GET /people 200 3.449 ms - 87

Attempting to Delete non-existing information results in a server response of 404 (not found).

Conclusion

This article gives an overview of sending a curl Delete task, clarifies its reason, and discusses its utilisation in evacuating indicated assets from a server. It talks about the Delete Ask strategy within the setting of web administrations and APIs, highlighting its noteworthiness in overseeing information and substances. The article presents a calculation for executing a Curl-Delete task with an illustration utilising a JSON server. It too incorporates sentence structure, programme code, and test yield. The article points to direct perusers on how to viably utilise Curl to perform Delete demands, enabling them to get the method and apply it in their claim server intelligence.

Updated on: 01-Aug-2023

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements