Knowledge Base Article

Home Page > Knowledge Base > Rapise

Home Page > Knowledge Base > Rapise > Rapise Web

Article Dynamically constructing the .rest file URLs to test REST APIs

by Adam S on Wednesday, December 9, 2015

Sometimes when using Rapise to test REST web services, you want to be able to dynamically change the base URL of the web service yet still use the same URL template and method information. This article describes a process for achieving this.
To illustrate a simplified version of this scenario, consider a REST service that consists of three methods that need to be tested across three applications running on three sites :

//Site 1

//Site 1 - Application 1

http://www.site-1.com/application-1/api/GetBook
http://www.site-1.com/application-1/api/SaveBook
http://www.site-1.com/application-1/api/DeleteBook

//Site 1 - Application 2

http://www.site-1.com/application-2/api/GetBook
http://www.site-1.com/application-2/api/SaveBook
http://www.site-1.com/application-2/api/DeleteBook

//Site 1 - Application 3

http://www.site-1.com/application-3/api/GetBook
http://www.site-1.com/application-3/api/SaveBook
http://www.site-1.com/application-3/api/DeleteBook

-----

//Site 2

//Site 2 - Application 1

http://www.site-2.com/application-1/api/GetBook
http://www.site-2.com/application-1/api/SaveBook
http://www.site-2.com/application-1/api/DeleteBook

//Site 2 - Application 2

http://www.site-2.com/application-2/api/GetBook
http://www.site-2.com/application-2/api/SaveBook
http://www.site-2.com/application-2/api/DeleteBook

//Site 2 - Application 3

------

//Site 3

//Site 3 - Application 1

http://www.site-3.com/application-1/api/GetBook
http://www.site-3.com/application-1/api/SaveBook
http://www.site-3.com/application-1/api/DeleteBook

//Site 3 - Application 2

http://www.site-3.com/application-2/api/GetBook
http://www.site-3.com/application-2/api/SaveBook
http://www.site-3.com/application-2/api/DeleteBook

//Site 3 - Application 3

http://www.site-3.com/application-3/api/GetBook
http://www.site-3.com/application-3/api/SaveBook
http://www.site-3.com/application-3/api/DeleteBook

//and so on

The solution is to use a template with parameters in the REST file for the variable parts of the URL:

"Url": "{Site}/{Application}/api/json/Method1",
...
 "Parameters": [
{
          "Name": "Site",
          "TokenName": "{Site}",
          "Value": null
        },
        {
          "Name": "Application",
          "TokenName": "{Application}",
          "Value": null
        }
      ]

For each method defined as above, the GET/POST/PUT/etc. would be defined along with additional token parameters (and default test values).

Then in the main Test js file, you need to loop over an array of sites and within this loop over an array of applications, and within this, iterate over each method name defined in saved_script_objects. That way the calls can happen and where necessary in separate test functions. Then you can override the default token values with specialized api calls specific to each method.

Attachments
Article Info
Last Updated: 12/9/2015
Article ID: KB181
# Views: 312
Powered by KronoDesk v1.1.0.15 | © Copyright Inflectra Corporation 2011-2016 | Licensed to Inflectra Corporation.