Skip to content

API Mock Tutorial: Applying Rules (Part 2)

Matthew Gallina edited this page Dec 12, 2019 · 12 revisions

In the previous section Applying Rules, we creating a simple authentication mock using rules.

In this section we will look at extending the /auth endpoint by adding further responses, to help mimic and deliver a more realistic service.


Updating the Mock

  • Open http://localhost:8000/index.html in your browser

  • Under the HTTP tab, locate the mock /auth and click the View button

  • From the HTTP Endpoint page, click on the Add Rule button

  • In the New Rule window enter the following:

    • application/json as the Content Type
    • 400 as the HTTP Status Code
    • {"msg" : "username is required"} in the Response Body
  • Click on the Add Rule Condition button

  • In the New Rule Condition window:

    • Select Request Parameter in the Match On field
    • Enter the value username in the field just below this
    • Select Is Missing in the Comparator field
    • Click the Add Arg button
  • Click the Done button and then the Add Rule button

You should now see 2 rules in the HTTP Endpoint page with this latest rule in 2nd place in the list (i.e Order is 2).

  • Looking closely at the rule in the list, you should be able to see 4 small icons; 2 arrows, a pause icon and a X.
  • Click on the up arrow on the 400 rule (we just added) so this is moved to position 1 (i.e it becomes Order no 1).
  • Lastly, click the Save button to update the mock.

Calling the Mock

Open a terminal window and run the following cURL command:

This should return a 400 response stating the username is required.


Next Step

Feeding Responses Remotely