Thursday, 9 August 2012

Introduction to REST

Two weeks back when I started reading about REST, there were thousands of articles available on Internet and after going through quite a many of them I finally found myself at the same position where I started. All of them were very informative but confusing as there were so many terms used like resources, verbs, nouns, blah blah blah…. I then decided to note down each term so that I can relate terms with each other while moving forward and gathered all the information below.
While working with traditional web services, we generally create web methods and expose them to our clients for their use. These web methods expects some kind of input from the client (in terms of string, integer, xml, etc.) in order to meet the required expectation.
Imagine a traditional web service which does not expose methods but exposes objects. An object does not have any input or output, which does not do anything because it is a NOUN not a VERB, a THING not an ACTION.
Let’s take an example of an automobile manufacturer ‘Volkswagen’ which exposes a method called ShowCarDetails( ). This method expects the car name as an input and gives the car details as output.
Think for an instance, in place of this web service, there is a new one which exposes car names as objects. So, when a client looks at it, instead of ShowCarDetails (), he will see POLO, VENTO, JETTA, PASSAT, etc. as objects. These objects don’t have any methods written for them to be invoked by clients. These objects (NOUNS) need to be acted upon with some action on them (VERB). In this case, in order to fetch the car details we will apply the GET (VERB) action on POLO (NOUN) to retrieve its details.
There is a term in OOPs called “Polymorphism” which says that a single verb can be applied to multiple nouns. This was the biggest challenge to identify the common verbs (actions) which can be applied to all the nouns (objects).  HTTP was the answer for this. HTTP is a "Protocol" which says: a client can send a request to a server which is either a GET or a PUT or a POST or a DELETE (there are other verbs as well – HTTP 1.1 supports 8 verbs). The entire web called as INTERNET works on these verbs only. So, if a web service that exposes only objects supports these four operations "on its exposed objects", any client should be able to do anything with that web service! This is what is called as REST.
REST is basically a term introduced by Roy Fielding in his Ph.D. dissertation to describe an architecture style of networked systems. REST is an acronym standing for Representational State Transfer.
If we go by the definition:
“REST exposes resources (sources of specific information), each of which is referenced with a global identifier (e.g., a URI in HTTP). In order to manipulate these resources, components of the network (user agents and origin servers) communicate via a standardized interface (e.g., HTTP) and exchange representations of these resources (the actual documents conveying the information).”
In many ways, the largest current world Implementation of REST is the INTERNET. RESTful applications use HTTP requests to post data (create and/or update), read data (e.g., make queries), and delete data. Thus, REST uses HTTP for all four CRUD (Create/Read/Update/Delete) operations.

REST is not a standard. One can only understand it and design his web services in that style. While REST is not a standard, it does use standards:
  • HTTP
  • URL
  • XML/HTML/GIF/JPEG/etc (Resource Representations)
  • text/xml, text/html, image/gif, image/jpeg, etc (MIME Types)
Now, going by the same example as used above, if we need to get details of Volkswagen car POLO we can get it by just using a URL as shown below (as an example):
"http://www.volkswagen.com/POLO"
When you will type this URL in browser, it will respond back to you with the required details in the pre-defined format as set up in the service (xml, text, json, etc.). Please note that the above URL will not actually work as this does not exist, I have used it as an example.
Much like Web Services, a REST service is:
  • Platform-independent (you don't care if the server is Unix, the client is a Mac, or anything else),
  • Language-independent (C# can talk to Java, etc.),
  • Standards-based (runs on top of HTTP), and
  • Can easily be used in the presence of firewalls.
Like Web Services, REST offers no built-in security features, encryption, session management, QoS guarantees, etc. But as with Web Services, these can be added by building on top of HTTP:
  • For security, username/password tokens are often used.
  • For encryption, REST can be used on top of HTTPS (secure sockets).
  • ... etc.
One thing that is not part of a good REST design is cookies: The "ST" in "REST" stands for "State Transfer", and indeed, in a good REST design operations are self-contained, and each request carries with it (transfers) all the information (state) that the server needs in order to complete it.
Conclusion:
REST is an architectural style which says to expose resources or objects to the consumers of the web service and allows the basic HTTP operation to be performed on them. In the next part of an this article, we will see detailed description about REST and how to create your first REST service.
References:
Representational State Transfer


REST Tutorial by Dr. M. Elkstein

REST and the Real World

Sunday, 5 August 2012

EAI Blues | Developer Vs Tester

After a couple of hard core technical entries, here is one which although is true in its own nature, but not heavy on the mind.

We all know and agree that Development and Testing teams are not always kind to each other. Till date, the reasons are unknown but everyone agrees that yes, there is a cold war.

In projects implementing EAI, Middleware solutions include numerous applications, end to end scenarios, business rules, multiple use cases, so the software testing part is truly a bigger challenge than development.

The main reasons resulting in multiple config defects, mapping defects, design changes, deployment failures can be attributed to the differences and absence of synergies between these two teams.

Testers keep opening defects on documents, test scripts, deployment manuals, mappings, result sets and keep complaining that the developers have not done a thorough job. Developers keep on saying the testers are a bunch of idiots who have little functional knowledge and do nothing but raise useless defects.
Amidst all this chaos, the issue is, that key functionality and business logics are often missed and defects arise in SIT or end to end or full data set testing.

So now, what can we do to avoid these defects in the first place? The answer according to experienced program managers is to treat both the dev and test team with equal importance and like two little brothers fighting for the candy. You should always pay equal importance to map the requirements of the testers and deliverables of the developers.

Furthermore below are some of the best practices that we can follow to ensure a 'Fast and Flawless' (a quote taken from my current company) delivery.

  • Involve resources from the testing team right from the beginning. It is better if they understand the Interface design as well, and like everyone always say ' See the Big Picture '.
  • They should have an approved test catalog by the time Interface design is complete. This is will help a lot while creating the test scripts and expected results.
  • Developers and Testers - Both these teams should do a cross review. Developers should get their deployment manuals and unit test cases reviewed by the Testing team, but the Testers should get the test scripts and expected results verified with a Business Analyst and NOT the Development team.
  • Developers tend to have a blind eye towards the result set. If the Interface has run fine, data has been published, there are no errors in the Logs, they WILL (I can tell you as I have been in development for 5 years) mark the test as passed without verifying if the data entered is absolutely correct. So ask the Developers to create expected results before unit testing, NOT after. (I have seen developers copying Interface execution results into expected results!!!!!)
  • Keep the documents UP TO DATE. People NEVER do it, big project, small project, big company, small company, 10 yr experienced, 1 yr experienced. Developers and Testers both tend to finish the work at hand, before they update the relevant documents which often results in the documents never been updated. The Program Manager should always and always make sure that the info in the repository is up to date.
  • Big or small, document or code, please please track all defects and make sure to analyze those defects on regular intervals to incorporate into best practices and guidelines.
That being it on a crude level, the talks are endless, viewpoints to the tunes of stars in the universe and standards like alien languages. There is no set rules for success, only a few guidelines and best practices that might help you reduce the risk and increase quality.

Thank you for your time and please do post your valuable comments to make the post and the blog more helpful.