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:

  1. check of incoming path (e.g. /my-route) and http method (e.g. GET)
  2. execution of validate function that determines whether a scenario is to be considered as valid given the current request context (e.g. taking requestHeaders and requestBody into consideration
572

🚧

The ordering matters

Stubr evaluates scenarios in the order they have been registered by you. The first scenario that Stubr evaluates as valid is used to answer the incoming request no matter of whether subsequent scenarios would be valid as well.


What’s Next