vADC Docs

Tech Tip: Using the RESTful Control API with PHP - deletepool

by ricknelson on ‎02-06-2014 09:23 PM - edited on ‎05-29-2015 09:41 AM by pwallace_1 (442 Views)

The following code uses Stingray's RESTful API to delete a pool.  The code is written in PHP and uses STMRESTClient.  This program deletes the "phptest" pool created by the addpool.php example.  To delete a resource you do a HTTP DELETE on the URI for the resource.  If the delete is successful a 204 HTTP status code will be returned.





# Delete a pool

require_once '';

$poolName = 'phptest';

try {

    # Set up the connection

    $client = new STMRestClient();

    /* Check to see if the pool exists.  If it doesn't exist, then a

     * ResourceNotFoundException exception will be thrown. */

    $response = $client->get("pools/$poolName");


    print("Pool $poolName deleted");

} catch (STMResourceNotFoundException $e) {

    # The pool doesn't exist

    print("Pool $poolName not found");

} catch (STMConnectException $e) {

    print ("Error connecting to the REST API: " . $e->getMessage());

} catch (STMAuthException $e) {

    print ("Error logging into the REST API: " . $e->getMessage());

} catch (Exception $e) {

    print ('Error: ' . $e->getMessage());





Running the example


This code was tested with PHP 5.3.3 and uses the STMRestClient class that can be found here: Tech Tip: A Stingray Traffic Manager REST Client for PHP


To run this program, Make it available via a web server and the output should be:


Pool phptest deleted


Read More