Overview
What is a Stubr scenario?
Stubr needs to know how to answer incoming API requests. For example, if you place a GET
request to /my-route
, Stubr needs to know whether...
- this route should be considered as existent
- it should allow for the
GET
method - which headers, body and http status code it should use for the response
Now routes could also have dynamic path segments, requests could require to be validated for mandatory parameters and responses could be required to be dynamic depending on incoming requests.
In Stubr these behaviours are modelled as scenarios
, which allow for efficient modelling of arbitrary API request/response behaviour.
How do scenarios work?
Incoming requests are evaluated against defined scenarios. The scenario evaluation is done in this sequence:
- check of incoming path (e.g.
/my-route
) and http method (e.g.GET
) - execution of
validate
function that determines whether a scenario is to be considered as valid given the current request context (e.g. takingrequestHeaders
andrequestBody
into consideration
The ordering matters
Stubr evaluates scenarios in the order they have been
registered
by you. The first scenario that Stubr evaluates asvalid
is used to answer the incoming request no matter of whether subsequent scenarios would be valid as well.
Updated almost 3 years ago