Information Technology - Blog V-Soft Consulting

How to Conduct Automation Testing of RESTful Web Services

Written by Charan Sai Dasagrandhi | Jul 24, 2019 9:28:21 AM

Representational State Transfer or simply REST is a architectural style for building web services. Web services built on REST architecture are termed as RESTful web services. In this blog, we discuss what RESTful is and how to perform automation testing of RESTful web services.

Understanding RESTful Web Services

REST is an interface between systems using HTTP to access and process data in another format, such as JSON or SML. In short, REST identifies the set of rules that must be implemented for creating Web Services. It acts similarly to a website in a browser. It accesses the URL and receives a web page in return. This page typically includes links that the user can click on to visit more pages, or even submitting a form to update the website, like signing up for blog updates.

REST's client-server separation of concerns simplifies component implementation, reduces the complexity of connector semantics, improves the effectiveness of performance tuning, and increases the scalability of pure server components."

- Roy Fielding, creator of the REST architectural style

Being an architectural style, it does not describe a message at all, however it specifies architectural requirements of that message, choreography the system must fulfill. REST is more data-driven, primarily designed to access resources. REST calls are capable of being cached.

Any web service that satisfies and follows the REST architectural style is called as RESTful Web Services.

*URI stands for Uniform Resource Identifier. It identifies the resources upon which to apply the request. URI consists of protocol schemas, host name, optional port, and optional fragment.

SOAP vs REST

SOAP and REST are two different types of API technologies, they are both developed to provide access to Web services.  Simple Object Access Protocol, better known as SOAP, is a messaging protocol that allows programs to communicate to one another via HTTP and XML, regardless of operating system. It specifies exactly how an HTTP or XML header should be encoded so both sides of the operation are capable of transferring information.

The most notable difference between SOAP and REST is that SOAP is a protocol, whereas REST is an architectural style. Some other important differences include:

  • The most obvious: SOAP is a protocol, whereas REST is an architectural style.
  • While REST calls are capable of being cached, SOAP-based calls can not.
  • As REST is simpler than SOAP, it is much easier to learn and utilize.
  • SOAP offers built-in error handling.

The right choice for the API development purely depends the requirement. Figuring out what is best for your API development depends on the requirements. If the requirement is about a lightweight and robust API that is mobile-friendly, then REST is preferable.

(Know in detail about SOAP vs REST)

Six Constraints Defining RESTful System

Below are Six Constraints the server can process and respond to client requests. If any system violates any of  these constraints, it’s not RESTful.

  • Client Server Architecture: By using client server architecture, the load is evenly distributed and it becomes easier for scalability.
  • Statelessness: In this the session state is being held on the client side and no client context is stored on the server between requests.
  • Web Cache / Cacheability: Temporary storage of web documents reduce server lags, thus ensuring local data availability based on past requests.
  • Layered System: Client cannot tell whether it is connected directly to end server or to intermediary.
  • Code on Demand: Servers can temporarily customize functionality of client by transferring executable codes such as Java applets or java scripts.
  • Uniform Interface: It simplifies and decouples the architecture so that each part can evolve independently.

Data retrieval and data security among websites is crucial and it's important to test RESTful Web Services. In order to do so one of the methods that we have is through HttpClient library.

RESTful Web Services Automation Testing Using Apache HttpClient

Maven dependencies should be imported in the maven project to test RESTful Web Services:

  • Apache HttpClient Library allows handling of HTTP Request. The main entry point of Apache HttpClient API is the HttpClient Interface.
  • CloseableHttpClient is an abstract class which implements HttpClient interface and java.io.Cloaseable interface.                                                               
  • HttpRequest have request line consisting of a method name, a request URI and HTTP protocol version.
  • HttpClient also provides URIBuilder() utility class.

Request URI is a uniform request identifier that identifies the resources upon which to apply the request. HttpResponse is a message sent by the server back to the client after having received and interpreted a request message.

Conclusion

REST architecture has high availability in the market and according to current market trends more applications are adopting REST architecture. It’s time to automate RESTful Web Services. 

About Author

Shireen Khan is a Senior Test Automation Engineer at V-Soft Consulting, with 5.8 years of experience.  In the course of her professional life, she played active role in winning strategic deals. She is skilled in Selenium WebDriver, TestNG, Maven, HP-UFT, HP-ALM, Git – GitHub, GitLab, Galen Framework, Rest API, Postman, Appium, and Jenkins. Also, she has good knowledge in Java Platform Standard Edition, C/C++, VBScript,  and HTML.