The Mocks Server can handle multiple behaviors, so you can change the API responses at your convenience while the server is running.
Each behavior consists in a set of "fixtures", which are handlers for specific requests. When a behavior contains multiple fixtures that should handle the same request (same method and url), the last one in the array will have priority over the first one. This has to be taken into account when we are extending behaviors.
Behaviors are defined with an object containing next properties:
<String>Used as reference for extending it, etc.
<String>Optional. Behavior id from which this behavior will extend.
<Array of String>Fixtures ids.
Behaviors are extensibles, so, you can have an "standard" behavior, which defines the default behavior of the mock server and responses for all your api uris, and extend this behavior creating new ones that change only responses for certain uris. All extended behaviors are extensible as well.
Behavior class, providing an array of "fixtures" or fixtures ids to it.
new Behavior(fixtures, options)
<Array>of fixtures or fixtures ids.
<String>Id for the behavior.
Read the "fixtures" code example to see how fixtures were defined first.
Behaviors instances contain an
You can add another one behavior extending the first one and changing only the response of the
updateUser fixture, for example:
Now, the server will have available "standard" and "update-user-error" behaviors.
The "update-user-error" behavior will send a different response only for the
/api/users/:id uri with
PUT method (supposing that
updateUserError fixtures have the same value for the