HTTP Request Methods

HTTP Request Methods: DELETE, PATCH

Table of Contents

DELETE method:

This HTTP Request methods is used to delete a resource which is present in the server. Sending the message body on a delete request will have because servers reject the request. But the data can be sent by using URL parameters to server. The delete method is called idempotent, that is if multiple delete requests can have the same effect on a single request. 

Consider an example for sending a delete request to the server.

The result is shown as

HTTP Request Methods

The server response is:

HTTP Request Methods

HTTP Request Methods: DELETE, PATCH

The sample example with respect to the database for delete request is

<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}

// sql to delete a record
$sql = "DELETE FROM My Guests WHERE id=3";

if ($conn->query($sql) === TRUE) {
  echo "Record deleted successfully";
} else {
  echo "Error deleting record: " . $conn->error;
}

$conn->close();
?>

PATCH Method:

A PATCH is considered as analogous to the update. A patch request will be considered a group of instructions on how to modify a resource. A patch need not be idempotent that is always any number need not be repeated. Identical requests will leave the resource in the same state. PATCH like PUT has some side-effects on other resources. 

Consider an example of patch request

HTTP Request Methods

HTTP Request Methods: DELETE, PATCH

A response will be indicated by any 2XX status code. An example of 204 response is considered as

HTTP Request Methods

HTTP Request Methods: DELETE, PATCH

Share this article
Subscribe
By pressing the Subscribe button, you confirm that you have read our Privacy Policy.
Need a Free Demo Class?
Join H2K Infosys IT Online Training