Lifecycle Hooks
What are Lifecycle Hooks?
A lifecycle hook is a way to add custom functionality during specific events in the life of a Stoobly resource such as a request or a response.
Stoobly's Lifecycle Hooks can be written as Python functions which use the Stoobly Python library to hook into these events and do addtional tasks.
Why use Lifecycle Hooks?
These hooks enable you to add custom functionality with your own code at different stages.
Some examples include:
Rewriting a header's value before or after its request gets sent to not store sensitive data
Adding, removing or modifying data such as in headers, query parameters, bodies, etc.
Adding extra debug information or publishing metrics
What are the Different Lifecycle Hook Events Supported?
For the full list, see this link to the Stoobly Python definitions of the events available. All of the strings on the right side of the variable assignment are also the function names available in lifecycle hook scripts.
Types of Contexts
There are several types of contexts available for your scripts. The parameter type will change depending on what type of hook you are using. To see the fields and methods available, view the full definition as well as any parent classes they might be inherited from.
RecordContext
For record events use the RecordContext
. The full definition can be found here.
To import it, add this to the top of your script:
ReplayContext
For replay events use the ReplayContext
. The full definition can be found here.
To import it, add this to the top of your script:
MockContext
For mock events use the MockContext
. The full definition can be found here.
To import it, add this to the top of your script:
Next Steps
Next see our guide on how to create your own lifecycle hooks and how to use them:
How to Create Lifecycle HooksLast updated