Skip to content

API Mock Tutorial: Feeding Responses Remotely

Matthew Gallina edited this page Dec 19, 2018 · 19 revisions

In this section we will explore how to create a mock that returns 'queued up' responses which are fed in from an external source.

To offer further explanation, this type of mock essentially utilizes 2 part:

  • The mocked service itself (i.e GET /helloworld), which the consumer will call to get any mock data.
  • An inbuilt service /proxy which is used to feed in responses that are later returned by GET /helloworld, when called (posting to this inbuilt service can also be done from within the UI).

Creating the Mock

  • Open http://localhost:8000/ in your browser

  • Under the HTTP tab click the New HTTP Endpoint button

  • From the New HTTP Endpoint page:

    • Enter /welcome under the Path field
    • Select GET under the Method field
    • Select HTTP External Feed as the mock type
    • Leave Long Polling Timeout as 0
  • Click the Save button

  • The new mock /welcome, should now be present under the HTTP tab in the dashboard

  • To deploy the mock to the mock server, click the play button (or stop and then start if the server is already running)


Calling the Mock

The call to /welcome should remain open, awaiting a response from the mock server.

  • You can supply a response by either using the UI or calling the /proxy endpoint...

    Using the UI

    • Open the /welcome mock from the dashboard
    • Expand the HTTP External Feed Tools drop down box
    • Enter the values:
      • application/json into the Content Type field
      • Enter 200 into the HTTP Status Code field
      • Enter {"name":"Hello, the wait is now over"} into the Response Body
    • Click the Post Response button

    Using the /proxy endpoint

    • Run the command:

      curl -H "Content-Type: application/json" -X POST -d '{"path":"/welcome", "method":"GET", "httpStatusCode":200, "responseContentType":"application/json", "body":"{"name":"Hello, the wait is now over"}"}' http://localhost:8000/proxy

You should finally see the message {"name":"Hello, the wait is now over"} appear as a response to the original call to /welcome.