Navigation: JunoRestClient > Advanced >

Property Transfer

 

Send comments on this topic.

 

 

Property Transfer

You can add groovy script to get response data, parse the required field and assign it to a variable. This variable can be used as template in URL field.

 

Example:

import groovy.json.JsonSlurper ;

def jsonSlurper = new JsonSlurper();

def documentName = "yourserviceName" ;

def responseJson = app.getResponsePayload(documentName) ;

def json = jsonSlurper.parseText ( responseJson ) ;

MY_PROPERTY_VARIABLE =  json.id ; // This is just an example to show you how to assign the variable value from the json result.

 

 

Sample JSON response data

{

    "id": 1,

    "userId": 1,

    "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",

    "body": "quia et suscipit"

}

 

 

 

Example with comments

 

//

//           Property Transfer Script to set VARIABLE which can be used as template in URL

//

 

import groovy.json.JsonSlurper ;

 

// Define jsonSlurper

def jsonSlurper = new JsonSlurper()

 

// Define REST service document name

def documentName = "yourserviceName" ;

 

// Get Response data

def responseJson = app.getResponsePayload(documentName) ;

 

// Parse JSON object from string

def json = jsonSlurper.parseText ( responseJson ) ;

 

//

//  Define global variable and set the property value you want to transfer.

//  The variable MY_PROPERTY_VARIABLE can be used in URL such as ${MY_PROPERTY_VARIABLE}.

//

MY_PROPERTY_VARIABLE =  json.id ; // This is just an example to show you how to assign the variable value from the json result.

 

Copyright © 2016 junorestclient.com

www.JunoRestClient.com