Service Virtualization

  • 1.  Sort response of rest API

    Posted Dec 08, 2017 11:49 AM

    Hi ,

     

    I am trying to virtualize rest api using request and response pair.

     

    request will be get trying to acess players of a team and response will give playes of team and in json format.

     

    but i want response to be sorted in alphabetical order of players.

     

    can this be done?

    Attachment(s)

    zip
    sample3-rsp.txt.zip   909 B 1 version
    zip
    sample3-req.txt.zip   272 B 1 version


  • 2.  Re: Sort response of rest API

    Posted Dec 08, 2017 12:47 PM

    Sorry, I am not aware of any OOTB filter, assertion, or step for sorting data in JSON arrays.

    Some options are:

    - Use live recording to capture the responses exactly as they are sent from the live system

    - Externalize the array into a DBMS, use a query to retrieve & sort the data, dynamically insert the array into the response object

    - Implement a script (JSR step or scripted assertion) to access the response JSON array and sort the results (e.g., Google GSON API) 

    - Sort the arrays in the rsp.txt file before running the R/R pair recorder

     

    I suppose it is possible to create a custom step that could sort the array. However, from a product perspective, identifying the elements to sort, which elements to exclude, and the element keys considered on the sort could create a lot of complexity. For example, does the script sort every element in the JSON (squad, team name, players, cache, provider, creditLeft, etc.), only team name, or a subset within the hierarchy (team name and players). By which key element does the logic sort, pid or name, and is the sort sequence ascending, descending, or a combination of both (i.e., sort teams in descending order, but player names within the team in ascending order)



  • 3.  Re: Sort response of rest API

    Posted Dec 08, 2017 01:04 PM

    only by player name



  • 4.  Re: Sort response of rest API

    Posted Dec 08, 2017 01:06 PM

    i found this doc but not able to understand. can you please help me with it.

     

     

    Sorting and filtering the response from your REST API 



  • 5.  Re: Sort response of rest API

    Posted Dec 08, 2017 01:46 PM

    Humm...  I'll have to take a look.   



  • 6.  Re: Sort response of rest API

    Posted Dec 08, 2017 01:49 PM

    sure. do let me know if you get anything.



  • 7.  Re: Sort response of rest API
    Best Answer

    Posted Dec 08, 2017 02:45 PM

    This must be feature implemented by Virtual API Cloud after the virtual response is selected. I do not see any similar feature / capability in DevTest 10.1. Perhaps, one of my colleagues has seen something different.