Saturday, January 22, 2011

Restlet Part II

In continuation from Restlet Part I, Part II includes three new katas that exercised the use of GET, PUT, and DELETE operators.  It was many times more difficult to implement because it required six different components to interact with each other:  a client, record of a client, in-memory persistent database, server for accessing the database, server for handling individual requests for a contact, and a server for handling requests for all contacts in the database.  More details can be found here.

Kata 5: Contacts resource
The task was to add a new resource that returns an XML representation of all the contacts in the database.  In other words, the contacts were stored in a Java collection and the goal was to transform it into an XML document.  At first I felt overwhelmed, but I identified the steps required to get the job done in about 4 hours:
  1. Create an XML document.
  2. Iterate through each contact in the collection, then attach it to the document.
  3. Return the XML document when the servers asks for this resource.
XML representation of contact resources in the database

Kata 6: Command line client manipulation of Contacts resource
The task was to extend the command line client functionality to include additional operators "get-all" and "delete-all". The get-all operation would retrieve all contacts in the database, retrieve their respective URLs, then print out contact information.  The steps required to do this was similar to Kata 5 but in reverse; an XML representation of a contact had to be transformed into its Java representation.  This kata took about 5 hours to complete because I had to look online and learn how to play with XML nodes.

Printout of contact information after calling the get-all operator

Kata 7: Add a telephone number to the Contact resource
The task was to extend the Contact resource to include a person's phone number.  In addition, the server would check to see if it was in the correct format ###-####.  If not, it would throw an error.  This kata was particularly easy and took about 1 hour to complete.

Error code 417 when the phone number does not adhere to the xxx-xxxx format

By completing these katas, I learned how to implement a RESTful client and server system that uses an in-memory persistent database.  I also improved my skills in performing meaningful unit testing to meet quality assurance standards.

A distribution of my work can be downloaded here.

No comments:

Post a Comment