Hooks
In this section, you will insert custom logic into your "environment template" using a HTTPS based hook. The HTTPS hook will be used to demonstrate a simple GET request to a well known endpoint.
You will implement the steps described below
- You will update your existing environment template from the prior step to use a HTTPS hook
- You will then launch the template and view the results of the hook
Step 1: Create Hook¶
In this step, you will update the existing environment template used in the previous step by adding a hook to the template. The hook will perform a simple HTTP GET request on a well known website to retrieve the content of the webpage.
- In your project, navigate to Environments -> Environment Templates
- Click on the name of the environment template
- Edit the template
- Navigate to Hooks
- Expand On Success section
- Click + Add Hook
- Enter a name for the hook
- Select HTTP for the Hook Type
- Enter https://www.google.com for the Endpoint
- Enter Get for the Method
- Enter the following for the success condition
if #status.http.statusCode == 200 {
success: true
reason: #status.http.body
}
if #status.http.statusCode != 200 {
failed: true
reason: "Did not get a 200 response code."
}
- Click Save as Draft
Step 2: Create Environment¶
In this step, we will create a new environment using the recently updated environment template. The environment will perform the same actions as before, however, during this run it will execute the HTTP hook.
- In your project, navigate to Environments -> Environments
- Click Launch on the environment template card
- Enter a name for the environment
- Enter a value for the username variable
- Click Save & Deploy
After the environment has been deployed, we will review the output of the newly added hook.
- Click Show next to Activities (Recent Runs)
- Expand the hook section
You will see the HTML output of the webpage that was used in our hook configuration.
Recap¶
In this part, you updated the the environment template to use a HTTPS hook that performed a simple GET request to an external endpoint.