-
Notifications
You must be signed in to change notification settings - Fork 24
API Mock Tutorial: Feeding Responses Remotely
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.
-
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)
- Open a terminal window and run the cURL command:
- curl -i -X GET http://localhost:8001/welcome (or simply open http://localhost:8001/welcome in a browser)
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.