Forum Discussion

ssin48's avatar
ssin48
Occasional Contributor
8 years ago

how to add query parameter values into a REST resource path through Groovy

how to add query parameter values into a REST resource path through Groovy

 

1. Is the below code correct to follow?

 

import com.eviware.soapui.support.types.StringToStringMap

def headers = new StringToStringMap()

headers.put("include", "value")
testRunner.testCase.getTestStepByName("REST Request").getHttpRequest().setRequestHeaders(headers)

 

 

2. Will this apend my resource path to include Query paramtere and is shown as below:

http://10.210.12.122:8080/mjo?include=value

4 Replies

    • ssin48's avatar
      ssin48
      Occasional Contributor

      This results in addition of a new header value - include.

      • nmrao's avatar
        nmrao
        Champion Level 3
        You mean duplicate header gets added each time?
  • Nastya_Khovrina's avatar
    Nastya_Khovrina
    SmartBear Alumni (Retired)

    Hi Sandeep,

     

    If I understand you right:

    1. No, this code can be used to add headers to a request: https://www.screencast.com/t/kK5M8IwRM
    2. To add query parameters to a request you can use the RequestFilter.filterRequest event and the following code:

     

     

    // get method so we can get the complete URI
    def method = context.getProperty( "httpMethod" )
    
    //log.info( method.URI.toString() )
    
    method.URI = new URI("http://10.210.12.122:8080/mjo?include=value?input=value")
    
    context.setProperty( "httpMethod", method )
    
    //log.info( method.URI.toString() )