Hoverfly allows you to recreate a sequence of different responses for a single request pattern by using stateful sequences. This is useful for testing endpoints that change behavior based on how many times they have been called or their current state.
To implement a sequence:
- Prefix the state key: Use the prefix
sequence: in your state keys (e.g., sequence:1). This tells Hoverfly the pair is part of a stateful sequence. - Define requirements: In the
request object, use requiresState to specify which step of the sequence the request must match. - Define transitions: In the
response object, use transitionsState to move the user to the next step in the sequence. - End of sequence: Once Hoverfly reaches the final response in the sequence, it will continue to return that final response for all subsequent matching requests.
{
"data": {
"pairs": [{
"request": {
"requiresState": {
"sequence:1": "1"
}
},
"response": {
"status": 200,
"body": "First response",
"transitionsState": {
"sequence:1": "2"
}
}
},
{
"request": {
"requiresState": {
"sequence:1": "2"
}
},
"response": {
"status": 200,
"body": "Second response"
}
}
]
},
"meta": {
"schemaVersion": "v5.2"
}
}