Contributions
Re: REST Mocking with Query Parametr
Open the request action. Change the Dispatch dropdown to SCRIPT You should then be able to script something like this: (actual working example from one of my mock services) // Match based on query parameter def queryString = mockRequest.getRequest().getQueryString() log.info "QueryString: " + queryString def response if (queryString !=null) { String[] fields = queryString.split('/&') fields.each { // Split each query string field into its key and value String[] kvp = it.split('='); def key = kvp[0]; def value = kvp[1] ; // Change the response depending on the value of nrd:AreaCode if( key == "nrd:AreaCode" ) { if( value == "7A1" ) { // return list of BCU GP Practices response = "Response - GP Practices - BCU" } else if( value == "7A2" ) { // return list of Hywel Dda GP Practices response = "Response - GP Practices - Hywel Dda" } } } } if (response != null) { log.info( "response: " + response) return response } Apologies in advance regarding coding conventions / style. I am not a Groovy expert but I thought a working example would be helpful8 years agoPlace ReadyAPI QuestionsReadyAPI Questions14KViews1like2Comments