REST Services


Welcome to ZAPTEST Tutorials! In this tutorial we will show you how to test REST API Services 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... A 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; the 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 Method Type - GET, and Data Format - XML. Next, we will add a step to our test by dragging the method into the Script View, and selecting the Execute operation. We will output the response to the test results. For this we will define a variable - "Response"; drag the "GetAllBooks" method from the API Explorer; and select the “GetStringResponse” operation. Next, we will add a Custom Reporting step, and use the variable's value in the step's detail argument. Now, we will save our test and run it. After the test run is finished, we will open the results and verify the response value with information about 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 Script View, and select the 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 “GetBook” API Method with the “GetMemberResponse” Operation. For arguments we will type "Author" and "Title" respectively. 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 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. In the method's URL we will replace hardcoded zero with a parameter placeholder Using the GET Parameters tab we will define a name and value for the new parameter. Now we will run 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 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 new Author and Title. We will add a step to our test 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 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

Tower Place 100

3340 Peachtree Rd NE #1800 

Atlanta, GA 30326 USA

(404) 814-5227