Forum Discussion

bkbn16's avatar
bkbn16
Contributor
9 years ago

Create Dynamic requests and create static responses for REST Mock services

I have created a REST Most service http://localhost:8080/rest/dashboard. Underneath this I have created 3 responses. All the responses are in JSON format. This is how it is ...

Resource Path: rest/dashboard

Output: 

{

'var' : '123'

}

Resource Path: rest/dashboard?id=10

Output: 

{

'var' : 'def'

'id':10

}

Resource Path: rest/dashboard?id=20

Output: 

{

'var' : 'cat'

'id': 20

}

So when I run the Mock services and hit the URL http://localhost:8080/rest/dashboard; it is giving me 

{

'var' : '123'

}

And also for http://localhost:8080/rest/dashboard?id=10 and also for http://localhost:8080/rest/dashboard?id=20; the output is keep changing as the Dispatch mode is in SEQUENCE. So I wrote a script and kept Default response as 

{

'var' : '123'

}

But I am unable to get any response from the forum for writing the grrovy as well(Groovy script must return the current HTTP URL). Can someone help me with these stubs creation.

  • It may like that you just run button mock service directly?

    But did you run actual request by point to mock service endpoint?
  • nmrao's avatar
    nmrao
    Champion Level 3

    You can achieve this using Script as Dispatch method.

    Wait I believe, you find it similar.

    • bkbn16's avatar
      bkbn16
      Contributor

      Thanks for the reply. I have tried this method earlier but I get "java.lang.NullPointerException: Cannot get property 'httpRequest' on null object" error while executing it. Do you know how to resolve this or why it appears ?

      • nmrao's avatar
        nmrao
        Champion Level 3
        It may like that you just run button mock service directly?

        But did you run actual request by point to mock service endpoint?