Service Virtualization

 View Only
Expand all | Collapse all

I have a requirement in my project to virtualise a restful API using devtest which uses GET....the main issue which I am facing is in creating the VSI for it as the API has json content in its URI itsef....How am I supposed to handle the various live requ

  • 1.  I have a requirement in my project to virtualise a restful API using devtest which uses GET....the main issue which I am facing is in creating the VSI for it as the API has json content in its URI itsef....How am I supposed to handle the various live requ

    Posted Aug 10, 2018 03:35 PM

    I have a requirement in my project to virtualise a restful API using devtest which uses GET....the main issue which I am facing is in creating the VSI for it as the API has json content in its URI itsef....How am I supposed to handle the various live requests which will have varying json content it as opposed to the VSI...Can someone please help in this??



  • 2.  Re: I have a requirement in my project to virtualise a restful API using devtest which uses GET....the main issue which I am facing is in creating the VSI for it as the API has json content in its URI itsef....How am I supposed to handle the various live

    Posted Aug 10, 2018 04:00 PM

    Is the JSON content inside a Query String parameter?

    Can you provide an example of the URI use on the GET call?

    If the content is in a Query String, you may need to use a combination of REST, RDM, and JSON DPHs where the REST DPH parses the query strings into arguments, the RDM copies or moves the query string parameter containing the JSON to the request body, and the JSON DPH parses the JSON string to complete building the Arg list. However, without an example to work from, this would be speculative at best.



  • 3.  Re: I have a requirement in my project to virtualise a restful API using devtest which uses GET....the main issue which I am facing is in creating the VSI for it as the API has json content in its URI itsef....How am I supposed to handle the various live

    Posted Aug 10, 2018 05:33 PM

    Hi Joel

     

    Appreciate the quick reply, I wont be able to provide the actual rest uri as it would land me in trouble with my client,but I could manage to find a similar looking REST URI on the net

     

    /app/restResource/%7B%22%22:%22123%22,%22tracks%22:%221234%22%7D

     

    it uses HTML encoding like %22 and %7B to denote { and " of the json format

     

    and the live requests will also contain these encoders

     

    Thanks 

    Arjit



  • 4.  Re: I have a requirement in my project to virtualise a restful API using devtest which uses GET....the main issue which I am facing is in creating the VSI for it as the API has json content in its URI itsef....How am I supposed to handle the various live

    Posted Aug 13, 2018 08:51 AM

    Give the following a try and see if it helps. This example uses two different R/R Pairs of input data based upon your scenario:

    Request 1:

    GET /app/restResource/%7B%22key%22%3A%22123%22%2C%22tracks%22%3A%221234%22%7D HTTP/1.1
    Host: api.themoviedb.org
    Accept: application/json

    <intentional blank line>

    Response 1:

    HTTP/1.1 200 OK
    Content-Type:application/json;charset=utf-8
    Connection:keep-alive

    {"key":"123","tracks":"1234"}}}

    Request 2: 

    GET /app/restResource/%7B%22key%22%3A%22abc%22%2C%22tracks%22%3A%221234%22%2C%22filter%22%3A%22no%22%7D HTTP/1.1
    Host: api.themoviedb.org
    Accept: application/json

    <intentional blank line>

    Response 2:

    HTTP/1.1 200 OK
    Content-Type:application/json;charset=utf-8
    Connection:keep-alive

    {"key":"abc","tracks":"1234","filter":"no"}

     

    1) Generate the sample R/R Pairs above, and save them in a directory

    2) Start the DevTest Workstation Recorder and build a Service from R/R Pairs

    3) Configure the Wizard according to HTTP protocol, select the R/R Pairs directory, etc.

    4) At the DPH configuration, add the following DPHs:

    - REST DPH is used to parse the URI, the URL Encoded payload for the above pairs is placed in URLPARAM0

    - The RDM DPH is used to move (or copy) URLPARAM0 to the Request Body. In this example, Copy was used.

    - The Scriptable DPH is used to decode the URL encoded Body to get the information into JSON format 

    - The JSON DPH parses the JSON payload after it has been decoded

     

    The generated VSI, based on the above R/R Pairs, has two different signatures. The URLPARAM0 argument was left in tact in the VSI because "Copy" was used rather than "Move" in the RDM DPH. In this case, URLPARAM0 contains the unaltered value that came in the request.

     



  • 5.  Re: I have a requirement in my project to virtualise a restful API using devtest which uses GET....the main issue which I am facing is in creating the VSI for it as the API has json content in its URI itsef....How am I supposed to handle the various live

    Posted Sep 05, 2018 11:14 AM

    Hello arjits.09,

     

    Did Joel's detailed response help you?

     

    Thank you,

    Heloisa