-
Notifications
You must be signed in to change notification settings - Fork 24
API Mock Tutorial: Applying Rules
Matthew Gallina edited this page Dec 6, 2018
·
21 revisions
Rules in sMockin are a great way to imitate real world behaviour in your HTTP mocks, by allowing you control the responses returned based on specific conditions.
In this section we will explore how to use Rules to simulate a simple login webservice.
-
Open http://localhost:8000/ in your browser.
-
Under the HTTP tab click the New HTTP Endpoint button.
-
From the New HTTP Endpoint page:
- Enter /auth under the Path field
- Select POST under the Method field
- Ensure select HTTP Rules Based as the mock type on the right hand side
- Enter application/json into the Default Content Type field
- Enter 401 into the Default HTTP Status Code field
- Leave the reminaing fields blank
What we have done so far is to define a default response which the /auth mock will return whenever none of rules have not been matched.
-
Next, click the Add Rule button
-
In the New Rule window enter:
- application/json as the Content Type
- 200 as the HTTP Status Code
- { "token" : "15bcd1a0-187d-4d2d-ae18-1e836fd87648" } in the Response Body
- Leave the Response Headers empty.
-
Click the Add Rule button
TODO