Showing results for 
Search instead for 
Did you mean: 

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

The following code uses Stingray's RESTful API to delete a pool.  The code is written in Ruby.  This program deletes the "rbtest" pool created by the addpool.rb 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.




require 'rest_client'

require 'base64'

require 'json'

poolName = 'rbtest'

url = '' + poolName

auth = 'Basic ' + Base64.encode64('admin:admin')


    # Try to delete the pool.  If it exists and is deleted we will get a 204. If it doesn't

    # exist we will get a 404, which will causue a resource.not_found exception

    response = RestClient.delete(url, {:authorization => auth})

    if response.code == 204

        puts "Pool #{poolName} deleted"


        puts "Bad status code #{response.code} when deleting pool"


rescue => e

    # If a 404 is returned then e.response will be a json object, otherwise it may not be

    if defined?(e.response)

        error = JSON.parse(e.response)

        if error['error_id'] == 'resource.not_found'

            puts "Pool #{poolName} not found"  


            puts "Error: URL=#{url} Error: #{e.message}"



        puts "Error: URL=#{url} Error: #{e.message}"




Running the example


This code was tested with Ruby 1.9.3 and version 1.6.7 of the rest-client module.


Run the Ruby script as follows:


$ delelepool.rb

Pool rbtest deleted


Read More


Version history
Revision #:
1 of 1
Last update:
‎03-27-2013 11:21:AM
Updated by:
Labels (1)