RESTful Web Services Developer's Guide

ProcedureExploring the Storage-Service Example

Once the service is deployed, it is a good idea to see how it works by looking at the contents of the containers, creating a container, adding content to the container, looking at the date and time stamp for the items in the container, searching for content in the containers, modifying content of an item in the containers, deleting an item from the container, and deleting the container. To accomplish these tasks, use the cURL command line tool, as shown in the following steps. cURL is a command line tool for transferring files with URL syntax.

  1. To show which containers currently exist, open a new terminal prompt and enter the following command. This command will henceforth be referred to as the GET command.

    curl http://127.0.0.1:9998/storage/containers

    The response is in XML format. Because there are no containers present, the response is an empty containers element.

  2. To create a container, enter the following at the terminal prompt:

    curl -X PUT http://127.0.0.1:9998/storage/containers/quotes

    This step creates a container called quotes. If you run the GET command from the previous step again, it will return information in XML format showing that a container named quotes exists at the URI http://127.0.0.1:9998/storage/containers/quotes.

  3. Create some content in the quotes container. The following example shows how to do this from the terminal prompt:

    curl -X PUT -HContent-type:text/plain --data 
    			"Something is rotten in the state of Denmark"  
    			http://127.0.0.1:9998/storage/containers/quotes/1
    curl -X PUT -HContent-type:text/plain --data 
    			"I could be bounded in a nutshell" 
    			http://127.0.0.1:9998/storage/containers/quotes/2
    curl -X PUT -HContent-type:text/plain --data 
    			"catch the conscience of the king" 
    			http://127.0.0.1:9998/storage/containers/quotes/3 
    curl -X PUT -HContent-type:text/plain --data 
    			"Get thee to a nunnery" 
    			http://127.0.0.1:9998/storage/containers/quotes/4 

    If you run the GET command again with /quotes at the end (curl http://127.0.0.1:9998/storage/containers/quotes), it will return information in XML format that show that the quotes container contains 4 items. For each item, the following information is displayed: digest, date last modified, MIME type, item name (also referred to as its key), and URI address. For example, the listing for the first item looks like this:

        <item>
            <digest>7a54c57975de11bffcda5bc6bd92a0460d17ad03</digest>
            <lastModified>2008-10-10T15:011:48+01:00</lastModified>
            <mimeType>text/plain</mimeType>
            <name>1</name>
            <uri>http://127.0.0.1:9998/storage/containers/quotes/1</uri>
        </item>
  4. You can search for information within the contents of the quotes container. For example, the following command would search for the String king.

    curl "http://127.0.0.1:9998/storage/containers/quotes?search=king"

    This returns the information for the item that contains the text, similar to that shown in the previous step, but not the text itself. The next step shows how to see the contents of the item containing the text king.

  5. To get the contents of the item containing the text you found using the search, use the following command:

    curl  http://127.0.0.1:9998/storage/containers/quotes/3

    This step returns the contents of item 3, which is the quote catch the conscience of the king.

  6. To delete an item from the container, use the following command:

    curl -X DELETE http://127.0.0.1:9998/storage/containers/quotes/3
  7. To delete an item from the container, use the following command:

    curl -X DELETE http://127.0.0.1:9998/storage/containers/quotes/3

    You can use the GET command to verify that item 3 has been removed.

  8. To delete the entire quotes container, use the following command:

    curl -X DELETE http://127.0.0.1:9998/storage/containers/quotes

    You can use the GET command to verify that the container has been removed.

  9. For a discussion of the caching of HTTP requests and responses, look at the as-install/jersey/samples/Storage-Service/README.html file.

    If you go back to the terminal window that is running the web storage service, you will see the history of HTTP requests and responses, which will look something like this:

    GET CONTAINERS
    PUT CONTAINER quotes
    GET CONTAINERS
    PUT ITEM quotes 1
    PUT ITEM quotes 2
    PUT ITEM quotes 3
    PUT ITEM quotes 4
    GET CONTAINER quotes, search = null
    PUT ITEM quotes 4
    PUT ITEM quotes 4
    GET CONTAINER quotes, search = king
    DELETE ITEM quotes 3
    GET CONTAINER quotes, search = null
    DELETE CONTAINER quotes
    GET CONTAINER quotes, search = null
    GET CONTAINERS