Service Virtualization

Expand all | Collapse all

How to have 2 different REST services with similar operations on the same port?

Jump to Best Answer
  • 1.  How to have 2 different REST services with similar operations on the same port?

    Posted 08-09-2018 10:30 AM

    I have 2 different REST services with the following operations:

     

    CreatePackage:  POST /api/packages

    AddDocument:   POST/api/packages/{DYNAMIC_PACKAGE_ID}/documents

     

    The base URL for CreatePackage has /api/packages and since AddDocument will have a dynamic value for package id, the base path is set to /.

     

    The problem is, if both services are on the same port (443 in this case), both requests try to call the CreatePackage service.  If I move AddDocument to port 444, then it gets called correctly.  

     

    Am I doing something wrong?  I'm assuming DevTest is seeing the /api/packages piece of the operation when calling AddDocument and quickly thinking it must be a CreatePackage request.



  • 2.  Re: How to have 2 different REST services with similar operations on the same port?
    Best Answer

    Posted 08-09-2018 10:45 AM

    Hello Robert,

     

    What about having one VSM with the same base path, /api/packages, and the VSI with the two different transactions - POST /api/packages and POST/api/packages/{DYNAMIC_PACKAGE_ID}/documents?

     

    In the Listen step, Filters, you should be using the REST DPH. Update the rules to match the two operations names you have in the VSI.

     

    You can find some rules examples in the link below:

    REST Data Protocol Handler - DevTest Solutions - 10.1 - CA Technologies Documentation 

     

    Hope it helps.

    Heloisa



  • 3.  Re: How to have 2 different REST services with similar operations on the same port?

    Posted 08-09-2018 10:49 AM

    Hi Rob,

     

    If multiple HTTP services are listening on the same port, they must be definitively distinguished by the base URL.  In the case of base URL of "/", you're effectively matching on everything.  So, you have two services which match on "/api/packages".  Which service will pick up a call to "/api/packages" is indeterminate.

     

    In your situation, I'd keep the base URL at "/api/packages" and merge the two VSIs.

     

    --Mike