Skip to content

API Mock Tutorial: Feeding Responses Remotely

Matthew Gallina edited this page Dec 13, 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.

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.

  • To supply a response, run the following 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.