Chapter 7. Adding behaviors
This chapter covers
- Programmatically postprocessing a response
- Adding latency to a response
- Repeating a response multiple times
- Copying input from the request into the response
- Looking up data from a CSV file to plug into a response
The basic is response is easy to understand but limited in functionality. Proxy responses provide high-fidelity mimicry, but each saved response represents a snapshot in time. Response injection provides significant flexibility but comes with high complexity. Sometimes, you want the simplicity of is and proxy responses with a touch of dynamism, all without the complexity of inject.
Software engineers who hail from the object-oriented school of thought use the term decorate to mean intercepting a plain message and augmenting it in some way before forwarding it on to the recipient. It’s like what the postal service does when it applies a postmark to your letter after sorting it. The original letter you sent is still intact, but the postal workers have decorated it to postprocess it with a bit of dynamic information. In mountebank, behaviors represent a way of decorating responses before the imposter sends them over the wire.
Because of their flexibility and utility, behaviors also represent one of the most rapidly evolving parts of mountebank itself. We’ll look at all of the behaviors available as of this writing (representing v1.13), but expect more to come in the future.