Tuesday, December 10, 2013

Performance testing on REST API

RESTful API has great promises in simplifying the development on web/smartphone apps and handling a larger number of clients. How can we effectively test servers that support RESTful APIs?

To load-test RESTful service, we need to be able to generate HTTP requests with methods like "PUT", "DELETE" etc. You are right, they may not be the familiar ones like GET, POST, but on NetGend platform, it's easy to emulate just about any HTTP method:

http.method = "PUT";
//or
http.method = "DELETE".

Note that by default, the http method is "GET" on NetGend platform, if you need HTTP POST method, you can simply do it by

Did you notice that the you don't have to escape the double-quotes in the template? On the other test platforms you may have to write { \"name\": \"john\", \"city\": \"Houston\", \"age\": \"23\"}? If you think escaping is a pain, you are not alone! Now you understand why I think it's a pleasure to do it on the NetGend platform.

The URL path for RESTful request may look like the following:/rest/8af909ffefa9/getDiston.json/10001/20002/mile, it can be generated in two ways.

//method 1, by variable substitution
/rest/${apiKey}/getDiston.json/${zip1}/${zip2}/${unit}
//assume you have the variables defined

HTTP responses for RESTful are increasingly in JSON format. Parsing JSON message is pretty simple on NetGend platform and has been covered many times in the previous blogs. The following is an example of JSON message from a site that implements a "todo" list.