How to perform a Guzzle DELETE request in PHP?

To perform a Guzzle DELETE request in PHP, you can follow these steps:

  1. Install Guzzle if you haven't already done so. You can install it using Composer by running the following command in your project's root directory:
composer require guzzlehttp/guzzle
  1. Once Guzzle is installed, you can use it in your PHP script by requiring the Guzzle library:
require 'vendor/autoload.php';
  1. Create a new Guzzle client instance:
$client = new \GuzzleHttp\Client();
  1. Use the client instance to send a DELETE request to the desired URL:
$response = $client->delete('https://example.com/api/resource/123');

Replace 'https://example.com/api/resource/123' with the actual URL you want to send the DELETE request to.

  1. You can retrieve the response status code and body as follows:
$statusCode = $response->getStatusCode(); $body = $response->getBody();

You can use $statusCode to check if the request was successful (e.g., $statusCode === 200) and $body to access the response body.

That's it! You have now performed a Guzzle DELETE request in PHP. Remember to handle any exceptions that may be thrown while sending the request.