REST Services

Welcome to ZAPTEST Tutorials! In this tutorial we will show you how to test REST API Services. During this lesson you will learn how to define REST API service calls, How to use GET and POST request types, and how to use XML and JSON data formats. In the tutorial exercise we will be using demo REST service provided by ZAPTEST for educational purposes. The server's address is displayed here... The description of services and methods can also be accessed in a browser via the help URL. In this lesson we will be using API requests under the Book section. We will start by defining a new API Server object. Here we will type a name for the server's object, demo REST server's URL, and click OK. To manually define a new API Method, we will press this button, type its name - "GetAllBooks", and enter the URL. For this method we will select the method type - GET, and Data Format - XML. Next, we will add this step to our test by dragging it into the Step View, and selecting the Execute operation. We will ouput the response to the test results. For this we will find and drag the local variable item from the toolbox; Type a name for the variable; drag the API method to the object's field; and select the “GetStringResponse” operation. Now we can add a Custom Reporting step, and use the variable's value in the step detail argument. Next, we will save our test and run it. After the test run has finished, we will open the results and verify the response value with information about the two books. We will continue by adding a new API method under the existing Server object. We will type "GetBook" for its logical name and enter the URL. For this method we will select Method Type - GET, and Data Format - XML. Next, we will add this method to the Step View, and select Execute operation. Like we did in the first part of our test, we will include steps to capture the response value, and output it to the test results. Now we well run the test again and review its results. The second response must include information about the first book only. Next, we will add steps to retrieve the book's author and title values individually. In these steps we will use the “GetMemberResponse” operation with "Author" and "Title" as its arguments. To output the Author and Title values we will add two custom reporting steps Now we will run the test and review its results The book author and title values must be displayed in separate steps. Next, we will change the data format for the “GetBook” call from XML to JSON, and rerun this test. The test result must display the response in the correct data format. In the next exercise we will parameterize the method's URL. We will replace the hardcoded zero with a parameter placeholder Using the GET Parameters tab we will define the name and value for the new parameter. Now we will run the same test one more time and review its results. The Author and title values must correspond to the specified value of the ID parameter. For our next exercise we will add a new REST API method; Type its logical name and the demo service URL. For the new method we need to keep type "POST", and select XML Data Format. To use the call for posting a new book information we need to specify its Body Data. Samples for the request can be found on the Help page. We will copy a sample provided for XML data format; And will use it to define the raw body data of the PostBook method. In the data text we will enter values for the new Author and Title. We will a add step by dragging the new method and choosing the Execute operation. The server response contains information about the new book, and we will add steps to capture its value and output it to the test results. Next, we will run our test and review its results. The step details must include the Author and Title that we defined in the Raw Body Data tab. In this tutorial lesson you have learned • how to use API Explorer to define REST service calls. • How to define and use GET and POST request types. • And how to use XML and JSON data formats. Thank you for using ZAPTEST.

Contact Us

1425 Market Blvd Ste 530 - 230

Roswell, GA 30076 USA

(800) 795-3552