Forum Discussion

sithariperera's avatar
sithariperera
New Member
9 years ago

I want to create a REST mock service with path parameters.

I want to create a REST mock service with path parameters. 

Something like http://localhost:8080/edit/{id}

 

Is this possible with Soap UI?

 

3 Replies

  • rupert_anderson's avatar
    rupert_anderson
    Valued Contributor

    Hi,

     

    If you mean can you set up a mock with a resource e.g. /quote/task/{id} so that you can do GET requests like /quote/task/12345. Then I would set the mock up like:

     

    Screen Shot 2015-10-02 at 13.27.16.png

    And then to get the id parameter value, use some Groovy script in the Dispatch(Script) e.g.

     

    def id = mockRequest.getPath().split("/")[-1]

    log.info "id: " + id

     

    Then you can use the id to selectively return responses:

     

    if (id=="12345") return "Quote12345Response"

     

    Or use it for other tasks or include it in the response etc.

     

    Is this what you mean?

    Cheers,

    Rupert

     

  • anil334's avatar
    anil334
    New Contributor

    Please try the below line:

    def requestPath = mockRequest.getPath();

    def reqPathLastVar = requestPath.substring(requestPath.lastIndexOf("/") + 1);

     

    the above lines worked fine even if if you deploy the war file on server.