Performancing Metrics

Vamsi Tokala's blog: Testing RESTful Web Services using LoadRunner

Thursday, May 6, 2010

Testing RESTful Web Services using LoadRunner

Brief overview of RESTful web services

REST defines a set of architectural principles by which you can design Web services that focus on a system's resources, including how resource states are addressed and transferred over HTTP by a wide range of clients written in different languages. If measured by the number of Web services that use it. REST has had such a large impact on the Web that it has mostly displaced SOAP- and WSDL-based interface design because it's a considerably simpler style to use.

From the standpoint of client applications addressing resources, the URIs determine how intuitive the REST Web service is going to be and whether the service is going to be used in ways that the designers can anticipate. A third RESTful Web service characteristic is all about the URIs.


REST Web service URIs should be intuitive to the point where they are easy to guess. Think of a URI as a kind of self-documenting interface that requires little, if any, explanation or reference for a developer to understand what it points to and to derive related resources. To this end, the structure of a URI should be straightforward, predictable, and easily understood.

One way to achieve this level of usability is to define directory structure-like URIs. This type of URI is hierarchical, rooted at a single path, and branching from it are subpaths that expose the service's main areas. According to this definition, a URI is not merely a slash-delimited string, but rather a tree with subordinate and superordinate branches connected at nodes. For example, in a discussion threading service that gathers topics ranging from Java to paper, you might define a structured set of URIs like this:

http://www.myservice.org/discussion/topics/{topic}

(Refer this article written by Alex Rodriguez on RESTful webservices for more information)

Sumilating RESTful web Services using LoadRunner


REST Services can be scripted using web_custom_request by adding appropriate headers using web_add_header function before the web_custom_request.

An example for REST services script is given below.


/*********************************

web_add_header ("X-ELS-APIKey","11111");

web_add_header ("X-Forwarded-For","12.5.28.133");

web_add_header ("Accept","text/xml");

web_custom_request("web_custom_request",

"URL=http://host:8080/content/abstract/*********",

"Method=POST",

"TargetFrame=",

"EncType=text/xml; charset=iso-8859-1",

"Resource=0",

"Referer=",

"Mode=HTTP",

"Body=",

LAST);

*****************************/

If you want to verify the response manually, you need to set up the header values first in your browser.

Please find below the steps for setting up the header using mozilla firefox browser.

  • Open firefox. Click "Add-ons" from tools menu
  • Click "get Add-ons" tab.
  • Type "HTTP header" in the text box for search all add-ons and enter.
  • In search results, click on "Add to firefox" for "Modify Headers 0.6.6" and install. Now you can see "Modify Headers 0.6.6" in the extension tab.
  • Click on "Modify Headers 0.6.6" from the "Extensions" tab and select the check box for "Always on" and "Open modify header in a new tab" and close.
  • Now click "Modify headers" from the firefox tools menu and add the appropriate header name and value for your request.

Now launch the URL in the firefox browser and verify the response manually.

Also refer RESTClient  addon available for firefox to test RESTful services

5 comments:

Anonymous said...

Hi
Thanks for the document. Could you please let me know how to capture the response from this. I need to pass the response as a header to the other service in continuation.

Regards,
SB

Vamsi Tokala said...

Capture using the typical Loadrunner functions and add append the response using web_add_header function

Anonymous said...

HI,

It is a great document and very helpful for beginners. I tried using this document for doing the testing on CXF services however my purpose is to send the POST request along with an XML request, I tried doing that with web_custom_method using BODY for providing the xml input. However, it fails there with error as Bad Request. Any clue?

Cheers
Lee

Vamsi Tokala said...

If you have a correct request format(Use Fiddler if required to capture it)
then compare it with Loadrunner request header and body to identify the reason for the bad request.

Anonymous said...

I am also trying a similar request and just ending up with a 500 error even before posting, but the End point URL is correct as it displays the WSDL properly