Restlet Continued….

REST Wiki
Assignment Link
Contact Service Source

In the previous blog post, I expressed my experiences with using the REST architecture to server as a date resource using the Restlet Java framework. Essentially, I found that using Restlet allows the manipulation of data source through XML rather than a connection to a SQL server using JDBC. I was impressed by the ability to handle requests using GET, PUT, and DELETE request methods to manipulate data on the a server instead of the traditional GET or POST request with parameters to a web page in order to manipulate the data on the server.

To extend my knowledge of the REST architecture, I implemented various functionality to an existing contact service to allow a user better manipulation of the server data. For this REST contact service, all the contact data was stored in memory to focus upon interfacing a resource request with the contact data instead of focusing on the contact data implementation. I will describe my experiences with exercise 5 through 7 below.

Kata 5:
For this exercise, I had to implement a REST resource which holds the URL to each contact inside the contact service’s data source. Essentially, the XML structure consists of a “contacts” XML tag encompassing a “contact” XML tag which holds the URL to the contact ID. This URL would be in the format such as http://localhost:8111/contactservice/contact/1. In this way, the contact’s information could be easily examined by pasting the link into a web browser.

Before this assignment, I have never used Java to parse an XML document before so I had a little bit of trouble figuring out the method of showing correct information. But by following the example for the contact service to look up a contact by ID, I was able to implement a contacts resource which output the latter XML structure.

Kata 6:
This kata extends upon the implementation of Kata 5 by using the contacts resource to act upon all the data source’s contacts. To complete this kata, I added some functionality to the ContactClient class. The latter class acts as a layer between the user and the contact server through the command line input. Thus, in order to implement this functionality, I added the new commands “get-all” and “delete-all” to GET or DELETE based upon the URL given in the contacts resource. After parsing the XML for the contact URL, I processed the user command by looping through all the URLs.

Kata 7:
As the last kata, I just needed to implement a new String variable in the Contact class to allow for phone number input. After modifying the Contact class to allow this new input, I verified the phone number against a Java Pattern “^(\d{3}-){1,2}\d{4}$”. Although this pattern does not accept every phone number such as international phone number, the point of this assignment is not to accept all variety of phone numbers, but to learn the method of verifying input to the contact service.

Because of my experiences with REST, I have taken a liking to its architecture. Why have web site’s not implemented the REST architecture especially in the case of file uploads? Why is the POST method still used to process file uploads?

Advertisements