Writing a REST Client in Perl

This tutorial will write a Perl script which removes a user from all open reviews – this might be useful if a reviewer is no longer available, and is holding up the completed status of all their reviews.

First install the REST::Client and JSON packages from CPAN – the details of doing this will depend on your platform.

Data::Dumper is very useful when developing Perl REST clients:

Our script will retrieve a list of all open reviews, get the uncompleted reviewers for each review, and if one of these matches the user passed as a command line parameter we will complete the reviewer.

  • Get all open reviews: GET /reviews-v1/filter/{filter}, setting {filter} to allOpenReviews.
  • Get the incomplete reviewers for each of these reviews: GET /reviews-v1/{id}/reviewers/uncompleted
  • Remove a reviewer: POST /reviews-v1/{id}/reviewers/{username}

When JSON produces lists of objects, the structures produced depend on the number of items in the list.
If the /reviews-v1/filter URL returns a single review, the JSON will look like this:

but if several reviews are returned the JSON will be:

and if there are no reviews it will simply be:

The toList function in the code below handles the three cases above.

Was this page helpful?

Have a question about this article?

See questions about this article

Powered by Confluence and Scroll Viewport