Test Automation for the REST API

With the REST architecture taking over the old MVC patterns, most API started using just one way to communicate with HTTP. Suddenly the business logic and any kind of data processing was done at the server and the client side was only responsible for representation of data and basic manipulations.


Testing of the REST API layer can be done using the REST-assured library that was developed by jay-way company. RESTful APIs generally are of two types: one returning XML responses and one returning JSON response. The assured - lib supports POST, GET, PUT, DELETE, OPTIONS, PATCH and HEAD requests and can be used to validate and verify the response of these requests.



You can add a flavor of BDD by using tools like cucumber or specflow:

When /^I send a GET request for "([^\"]*)"$/ do |path|
  get path
end

When /^I send a POST request to "([^\"]*)" with the following:$/ do |path, body|
  post path, body
end

When /^I send a PUT request to "([^\"]*)" with the following:$/ do |path, body|
  put path, body
end

When /^I send a DELETE request to "([^\"]*)"$/ do |path|
  delete path
end

Then /^the response should be "([^\"]*)"$/ do |status|
  last_response.status.should == status.to_i
end

Then /^the response JSON should be:$/ do |body|
  JSON.parse(last_response.body).should == JSON.parse(body)
end

Comments

  1. Anonymous3/6/16

    Test Automation for the REST API Thanlku for sharing about this...
    Best SEO training in hyderabad,training by professional experts during experience more than 15 years,and Giving placement in their company.And giving knowledge of All digital marketing modules with professional practise.Train by expert and Earn huge money per month.Best SEO training in hyderabad

    ReplyDelete
  2. Thanks for the info! Can you please suggest tools for API testing automation?

    ReplyDelete
  3. Anonymous14/3/19

    REST API is a set of functions helping developers in performing requests along with receiving responses. Through HTTP protocol interaction is made in REST API.

    The term REST refers to Representational State Transfer. In very short span of time, it has become an effective standard for API creation.

    Thanks for sharing such a valuable post and Keep Sharing !!!!

    Error Free API testing

    ReplyDelete

Post a Comment

Popular posts from this blog

Software Testing @ Microsoft

Trim / Remove spaces in Xpath?