Service Virtualization

Expand all | Collapse all

How to extract the query parameters in Rest Request

  • 1.  How to extract the query parameters in Rest Request

    Posted Jul 03, 2017 05:37 AM

    I'm trying to create a VS with Rest data protocol wherein by using different http methods, the response is directed to respective transactions. The issue is I'm unable to extract the query Parmeter (1234 viz the EmployeeId). I tried extracting via {{=request_EmployeeId}}, but it's not working, Can someone please help. 

     

    POST http://localhost:9789/employee 

    GET http://localhost:9789/employee/1234 

    UPDATE http://localhost:9789/employee/1234 

    DELETE http://localhost:9789/employee/1234 



  • 2.  Re: How to extract the query parameters in Rest Request

    Posted Jul 03, 2017 06:10 AM

    you can use REST data protocol to extract URI parameter. In your scenario, add an operation in REST as 

    GET /employee/{empId} and add empId as an argument in your vsi.

     

    which version of DevTest are you using ?



  • 3.  Re: How to extract the query parameters in Rest Request

    Posted Jul 03, 2017 06:14 AM

    Thanks Syed. I'm using 10.1

     

    Let me try this.



  • 4.  Re: How to extract the query parameters in Rest Request

    Posted Jul 03, 2017 06:23 AM

    I tried making empId as an argument. Seems am doing something wrong. No arguements are being captured here

     

    {"id":0,"operation":"GET /employee/1003","arguments":{}}



  • 5.  Re: How to extract the query parameters in Rest Request

    Posted Jul 03, 2017 07:03 AM

    Hope you are using REST DPH. I have attached the snapshot of VSM and VSI.

     



  • 6.  Re: How to extract the query parameters in Rest Request

    Posted Jul 03, 2017 07:11 AM

    Exactly this is how I'm using it, but unable to capture the value of EmpId, please see the screenshots



  • 7.  Re: How to extract the query parameters in Rest Request

    Posted Jul 03, 2017 06:45 AM

    Query Parameters will start after ? and are name value pairs.

    While creating a VSI with rr pairs use

    GET /employee?employeid=1234 

     

    Thanks,

    Venkatesh



  • 8.  Re: How to extract the query parameters in Rest Request

    Posted Jul 03, 2017 07:12 AM

    True Venkatesh. However I'm trying the query parameters directly.



  • 9.  Re: How to extract the query parameters in Rest Request

    Broadcom Employee
    Posted Jul 04, 2017 03:48 AM

    Validate that the request arguments that you want to use are marked as magic string in the request tab.

    Everything marked as magic string can then be used in the response tab as {{request_<argumentName>}}

    So in your case based on the last screenshot you provided the following should work {{request_URLPARAM0}}



  • 10.  Re: How to extract the query parameters in Rest Request

    Posted Jul 04, 2017 05:17 AM

    Hey Danny. I'm not using any additional parameter as a part of payload, passing only one parameter as a part of URL. The strange part is it is giving the value in response when I use {{request_URLPARAM0}} in VSI, however trying out the same in VSM, isn't capturing the value

     

     



  • 11.  Re: How to extract the query parameters in Rest Request
    Best Answer

    Broadcom Employee
    Posted Jul 04, 2017 07:34 AM

    It is not straightfoward to see from the printscreens what you are doing where exactly. I’ll give some thoughts based on what I think is happening.

     

    If {{request_URLPARAM0}} has a value within the .vsi, i.e. within the “Response Selection” step and this is due to magic stringing then that property request_URLPARAM0 will NOT exist in any step prior to the “Response Selection” step.

     

    If you need to work with request_URLPARAM0 before the Response Selection step then you need to add a Request Data Copier DPH after your REST DPH and copy the arguments to “request_” properties.

     

    Then in the scripted assertion: to my knowledge the script is not parsed before it is executed, so I don’t think that using {{request_URLPARAM0}} will work.

     

    Within the script the property request_URLPARAM0 will exist and have a value if it exists in testExec. Wherever it is encountered as a variable the BeanShell will treat it as an existing variable. However, you are using it inside a fixed string and the characters {{request_URLPARAM0}} are just considered as part of a string.

     

    It would do it as:

     

    String query = “Select * from EmplyeeTest where EmployeeId = ‘” + request_URLPARAM0 + “’”;

    testExec.setStateValue(“query”, query);

     

    Cheers,

    Danny