Forum Discussion

listentorick's avatar
16 years ago

Howto create a mock service to serve static json

Hi,

I would like to be able to use soap ui to serve json from a mocked restful service.

All I have is some JSON - I don not have a url exposing a wsdl/wadl yet.

This is because I am developing the browser based application without access to the main application - all I have is some JSON in an agreed format.

I've looked at the documentation which implies that it is possible to mock restful services which return JSON, however all the examples work with a wadl.

How do I create a mock service when all I have is a set of JSON responses?

1 Reply

  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    You can create a MockService and put code like the following in the OnRequest script:


    def json = """{
        "firstName": "John",
        "lastName": "Smith",
        "age": 25,
        "address": {
            "streetAddress": "21 2nd Street",
            "city": "New York",
            "state": "NY",
            "postalCode": "10021"
        },
        "phoneNumber": [
            { "type": "home", "number": "212 555-1234" },
            { "type": "fax", "number": "646 555-4567" }
        ]
    }
    """

    def response = mockRequest.getHttpResponse()
    response.setContentType("application/json")
    def writer = response.getWriter();
    writer.write(json)
    writer.close()