Version: 1.6.0
Fixtures
#
DefinitionA "fixture" defines the handler for an specific request and the response to be sent.
The standard format for defining a fixture is to declare an object containing next properties:
url
:uri as <String>
Uri of the resource. It can contains expressions for matching dynamic uris. Read the route-parser documentation for further info about how to use dynamic routing.method
:<String>
Method of the request. Defines to which method will response this fixture. Valid values are http request methods, such as "GET", "POST", "PUT", etc.response
:<Object>
Defines the response that the server will send to the request:status
:<Number>
Status code to send.body
:<Object>
Object to send as body in the response.
response
:<Function>
Response can be defined as a function too. The function will receive the expressrequest
,response
andnext
arguments, so you are free to handle the request at your convenience. This is what we call a "dynamic" fixture.
#
ExamplesIn the next example you can see how static and dynamic fixtures are defined:
More formats for defining fixtures can be added to the Mock Server. Read the custom fixtures handlers chapter for further info.