API - SOAP and REST

Prev Next

Overview

Catchpoint API monitoring supports SOAP and REST. These are the two most dominant design models for web services. In this article, you will find a detailed information about SOAP and REST, and how to implement them in Catchpoint using Selenium API test.

Simple Object Access Protocol (SOAP):

SOAP relies exclusively on XML to provide messaging services. XML is used both to make requests and receive responses in SOAP. In some programming languages, those requests must be built manually. This is problematic due to SOAP’s intolerance of errors. One of the most important SOAP features is built-in error handling. If there’s a problem with your request, the response contains error information that can be used to address the problem.

Representational State Transfer (REST):

REST provides a lighter-weight alternative to SOAP. Instead of using XML to make a request, REST relies on a simple URL in most cases. REST can use four different HTTP 1.1 verbs (GET, POST, PUT, and DELETE) to perform tasks. REST doesn’t have to use XML to provide the response. REST-based Web services that output the data are available in Command Separated Value (CSV), JavaScript Object Notation (JSON) and Really Simple Syndication (RSS), providing the needed output in a format that is easy to parse within the application's language.

Building a SOAP/REST Script:

Verbs used for building a SOAP/REST script are:

  • open()
  • setNavigatePostData()
  • setHeader()
  • assertHttpResponseCode()
  • setStepName()

Verb definitions are provided below.

open()
Opens a page using a URL. For API it can accept a 2nd parameter to allow for setting the HTTP method type [default="GET"].

setNavigatePostData()
The parameter specifies the POST data to send for the root-request.

setHeader()
Used for dynamically assigning a particular HTTP request header for either the root-request (when no child-request-pattern is used) or child-requests (if the child-request-pattern is used). The 1st parameter specifies the header-key and optional child-request-pattern and the 2nd parameter the header-value.

assertHttpResponseCode()
Validates the root-request's response-code.

setStepName()
This is used for naming a given transaction step.

Example: SOAP

//Set the request URI.
Open('https://www.apitest.com/path.asmx')

//Build POST data for the request, for SOAP its XML data.
SetNavigatePostData ("<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><Login2 xmlns=\"http://wsi.com/fusion/\"><customerID>1</customerID><username>user1</userName><macAddress>none</macAddress><password>password1</password><version>2</version></Login2></soap:Body></soap:Envelope>")

//Set the request headers.
setHeader('Content-Type', 'text/xml')

//Assert for response code.
assertHttpResponseCode("200")

//Set the step name.
SetStepName('1. API call SOAP')

Example: REST

//Set the request URI.
Open('https://www.apitest.com/path.asmx')

//Build POST data for the request, for REST its commonly JSON data.
SetNavigatePostData("[{"selectedFulfillment":{"shipping":{"address":{"firstName":"test","middleInitial":"","lastName":"Latency","street":"1000 Example Ave S","street2":"","city":"New York","state":"NY","zipcode":"10010","dayPhoneNumber":"1234567890","useAddressAsBilling":true}}},"id":"ci69119342344"}] ")

//Set the request headers.
setHeader('Content-Type', ' application/json; charset=UTF-8 ')

//Assert for response code.
assertHttpResponseCode("200")

//Set the step name.
SetStepName('1. API call REST')