A Perl Client Against a Java RESTful Web Service
The Perl client (see Example 3-1) against the Java predictions2 RESTful service, implemented as an HttpServlet, makes
various calls that cover the CRUD operations. (The predictions2 service is from Chapter 2.)
Perl comes with most Unixy systems and is available on Windows (see, for
example, ActiveState). Although Perl has a quirky syntax—it has been called line-noise interpreted and even worse—its
excellent libraries, standard and
contributed, more than compensate. In any case, the point of the example is to provide a first look
at how a client interacts with a RESTful service. The curl clients from the two previous chapters illustrated all of the
CRUD operations against several services; all of the CRUD requests received at least a minimal document in return. Yet the
curl utility is meant for making HTTP requests, not processing HTTP responses.
The Perl client takes the second step; that is, this client performs all of the CRUD operations and then highlights the challenge of
processing response documents. In the case of response documents in XML, the Perl client parses the XML to extract usable
information, in this case the id, who, and what of a specified Prediction or of the entire PredictionsList returned from
the service.
Example 3-1. A Perl client making CRUD calls against the RESTful predictions2 service
#!/usr/bin/perl-w#packagesusestrict;useLWP;useXML::XPath;useList::MoreUtilsqw(each_array);my$baseUrl='http: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access