Service Virtualization

  • 1.  How to use request parameter in response?

    Posted Feb 16, 2016 03:01 AM

    Hello,

     

    I have a request parameter objectId in the form /v1/getProduct/{objectId}. I want to use this objectId in the JSON response to display appropriate message like:

    {

    "status": 404

    "error": "Not Found"

    "message":"{objectId} is not found"

    }

    How do I store objectId in a variable and use that in response? I'm using DevTest 9.0

     

    Thanks.



  • 2.  Re: How to use request parameter in response?
    Best Answer

    Posted Feb 16, 2016 03:57 AM

    Hi Sharath,

     

    If your Virtual Service is created correctly, your request should already have an argument created for this parameter (by default it is named URLPARAM0. )

    Each argument value is automatically saved by Devtest into a property by the name request_<arg_name> , in this case it will be called request_URLPARAM0

     

    You can change your response to contain the following

    {

    "status": 404

    "error": "Not Found"

    "message":"{{request_URLPARAM0}} is not found"

    }

     

    Hope that helps

    Regards

    Tanveer



  • 3.  Re: How to use request parameter in response?

    Posted Feb 16, 2016 01:31 PM

    Thanks Tanveer. It worked!