Skip to main content

Web Services Builder in Katalon Studio

RestRequestObjectBuilder class provides functions to create a RESTful object easily and quickly in scripting view. You can find details regarding to API docs specifications here: [Java] Class RestRequestObjectBuilder.

TypeName and description
RequestObjectbuild()
RestRequestObjectBuilderwithFileBodyContent(String filePath)

Specify the binary body content

RestRequestObjectBuilderwithHttpHeaders(List<TestObjectProperty> httpHeaderProperties)

Specify HTTP headers for the request object

RestRequestObjectBuilderwithMultipartFormDataBodyContent(List<FormDataBodyParameter> parameters)

Specify the body content for multipart/form-data type, default charset UTF-8

RestRequestObjectBuilderwithRequestAuthorization(RequestAuthorization requestAuthorization)

Specify the authorization for the request object (available from version 8.4.0 beta)

RestRequestObjectBuilderwithRestParameters(List<TestObjectProperty> restParameters)

Specify the REST parameters for the request object

RestRequestObjectBuilderwithRestRequestMethod(String requestMethod)

Specify method for the request object

RestRequestObjectBuilderwithRestUrl(String url)
RestRequestObjectBuilderwithTextBodyContent(String text)

Specify the text body content, default charset UTF-8

RestRequestObjectBuilderwithTextBodyContent(String text, String charset)

Specify the text body content

RestRequestObjectBuilderwithUrlEncodedBodyContent(List<UrlEncodedBodyParameter> parameters)

Specify the body content that composes of a list of url-encoded pairs, default charset UTF-8

RestRequestObjectBuilderwithUrlEncodedBodyContent(List<UrlEncodedBodyParameter> parameters, String charset)

Specify the body content that composes of a list of url-encoded pairs

Examples regard how to use them:

  1. Create a GET RESTful request
    import com.kms.katalon.core.testobject.ConditionType as ConditionType
    import com.kms.katalon.core.testobject.RestRequestObjectBuilder
    import com.kms.katalon.core.testobject.TestObjectProperty as TestObjectProperty
    import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS

    'Create a new GET object using builder'
    def builder = new RestRequestObjectBuilder()
    def requestObject = builder
    .withRestRequestMethod("GET")
    .withRestUrl("http://jsonplaceholder.typicode.com/comments")
    .withRestParameters([
    new TestObjectProperty("postId", ConditionType.EQUALS, "1"),
    new TestObjectProperty("id", ConditionType.EQUALS, "1")
    ])
    .withHttpHeaders([
    new TestObjectProperty("Content-Type", ConditionType.EQUALS, "application/json")
    ])
    .build()
    'Send a request'
    def response = WS.sendRequest(requestObject)

    'Verify if comment\'s email after sending request is correct or not'
    WS.verifyElementPropertyValue(response, '[0].email', 'Eliseo@gardner.biz')


  2. Create a POST RESTful request

    import com.kms.katalon.core.testobject.ConditionType as ConditionType
    import com.kms.katalon.core.testobject.RestRequestObjectBuilder
    import com.kms.katalon.core.testobject.TestObjectProperty as TestObjectProperty
    import com.kms.katalon.core.testobject.UrlEncodedBodyParameter
    import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS

    def builder = new RestRequestObjectBuilder()

    'Create a new POST object using builder'
    def requestObject = builder
    .withRestRequestMethod("POST")
    .withRestUrl("https://sample-web-service-aut.herokuapp.com/api/users/urlencoded")
    .withHttpHeaders([
    new TestObjectProperty("Content-Type", ConditionType.EQUALS, "application/x-www-form-urlencoded")
    ])
    .withUrlEncodedBodyContent([
    new UrlEncodedBodyParameter("username", "myUsername"),
    new UrlEncodedBodyParameter("password", "myPassword"),
    new UrlEncodedBodyParameter("gender", "MALE"),
    new UrlEncodedBodyParameter("age", "20"),
    new UrlEncodedBodyParameter("avatar", "AAA"),
    ])
    .build()

    def response = WS.sendRequest(requestObject)

    assert response.getStatusCode() == 200
  3. Send request with NTLM authorization (version 8.4.0 beta onwards)
    import com.kms.katalon.core.testobject.RequestObject
    import com.kms.katalon.core.testobject.ResponseObject
    import com.kms.katalon.core.testobject.RestRequestObjectBuilder
    import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
    import com.kms.katalon.core.testobject.authorization.NTLMAuthorization
    NTLMAuthorization ntlm = new NTLMAuthorization("your_username", "your_password", "", "")
    RequestObject ro2 = new RestRequestObjectBuilder()
    .withRestUrl("your_URL")
    .withRequestAuthorization(ntlm)
    .withRestRequestMethod("GET")
    .build()

    ResponseObject respObj2 = WS.sendRequest(ro2)