The VersionSamples example also shows how to set up the REST request with all the required information. Although you can make this same request through a browser (see Testing REST requests with a browser), it is helpful to see how it works through this Perl application.
So, let’s go through the important parts of the Perl code.
First, on lines 62-63, you declare the variables used for the HTTP POST command and used for handling the returned data in XML format.
my $ua = new LWP::UserAgent;
my $xml = new XML::Simple (KeyAttr=>[]);
LWP::UserAgent manages HTTP connections and performs requests for you. The xml variable is set to handle the returned XML, and to assign name elements in order to make it easier to access each node.
In line 66, you make the request.
my $response = $ua->post($BASE_URL.'rest/standard/version');
Here, you send the specified endpoint using the POST command. With REST, the operation, version, is automatically included with the service. If there are any parameters, you can pass them here as well. For example:
my $response = $ua->post($BASE_URL.'rest/standard/searchCatalog',
{clientID=>$clientID,
term1=>$searchTerm});
This example shows how you can add the parameters to the base endpoint. In making this same request through the browser URL, you append a question mark (?) after the operation in order to indicate the start of the parameters; the parameters are then separated by an ampersand (&). In the Perl application, you can referencing the values of the variables as part of the post function.
For the VersionSamples application, the final step (in line 70) is to print the content.
print $response->content."\n";
This line just dumps the content to the display as raw XML.
© 2009-2012 SirsiDynix