Skip to content

Commit be300b7

Browse files
changed alt text and added two small explanations
1 parent 4f0f984 commit be300b7

File tree

1 file changed

+11
-11
lines changed
  • docs/docs/08_flask_jwt_extended/11_insomnia_request_chaining

1 file changed

+11
-11
lines changed

docs/docs/08_flask_jwt_extended/11_insomnia_request_chaining/README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,40 @@ Up until now, we've been able to log in, get an access token, and then use that
1111

1212
Instead of passing the JWT in every request, you can access the `Headers` section and follow these steps. In the `Authorization` field, type `Bearer` add a space and then press `CTRL + SPACE` to get a contextual menu. Navigate to the `Response -> Body Attribute` field and select it, as shown in the screenshot below:
1313

14-
![Adding Body Attribute](./assets/bearer_token.png)
14+
![Contextual menu with Generator Tag options](./assets/bearer_token.png)
1515

1616
After you've selected it, you'll see an error that looks like this:
1717

18-
![Error](./assets/error.png)
18+
![Response error](./assets/error.png)
1919

2020
If you click on the error, you'll see a modal window:
2121

22-
![Modal](./assets/modal.png)
22+
![Empty modal window](./assets/modal.png)
2323

24-
Inside of this window, there is a `Filter` field. In this field, we are telling Insomnia which part of the response we want to get from it. The prompt is started with the dollar sign `$` and then we can use the dot to access the attributes of the response. If we only type `$` or `$.`, we'll get a list of all the attributes of the response:
24+
Inside of this window, you will first need to select a request that you want to get the data from. Click on `Select item` inside the `Request` field and choose the `POST /login` endpoint. After you've done that, go to the `Filter` field. In this field, we are telling Insomnia which part of the response we want to get from it. The prompt is started with the dollar sign `$` and then we can use the dot to access the attributes of the response. If we only type `$` or `$.`, we'll get a list of all the attributes of the response:
2525

26-
![Attributes](./assets/attributes.png)
26+
![Attributes recieved from request using a dollar sign](./assets/attributes.png)
2727

2828
In our case, we want to get the `access_token` attribute from the response, so we type `$.access_token`. If there was something else inside the `access_token` that you wanted to access like some value for example, you could do `$.access_token.value` and so on. After you've added the filter, you can set the `Trigger Behavior`. For example, you can set it to `When expired` and set time to 300 seconds. This means that the token will be refreshed every 5 minutes. The filled out window should look like this:
2929

30-
![Filled out](./assets/filled_out.png)
30+
![Filled out modal window](./assets/filled_out.png)
3131

3232
You can now press `Done` and you'll see that the error is gone and that the `Authorization` field is filled out with the `Bearer` token:
3333

34-
![Filled out](./assets/token.png)
34+
![Filled out Authorization field with Bearer token](./assets/token.png)
3535

3636
Since we use multiple protected endpoints, we would need to use the same method to get the `access_token` for every request. To tackle this problem, we can use [environment variables](https://support.insomnia.rest/article/13-environment-variables), as we did before for the `url` variable.
3737

3838
To do this, you need to create a new environment variable. Click on the `No Environment` button in the top left corner of the Insomnia window and then click on the `Manage Environments` button, you will see a base environment that looks like this:
3939

40-
![Base environment](./assets/base_environment.png)
40+
![Base environment with url env variable only](./assets/base_environment.png)
4141

42-
Add a new environment variable called `access_token`, and for its value you should follow the same process from above. Make sure to wrap the `Response -> Body Attribute` with quotation marks, as shown in the screenshot. When the variable is created, your environment should look like this:
42+
Add a new environment variable called `access_token`, and for its value you should follow the same process from above. As a quick reminder, you should press `CTRL + SPACE` to get the contextual menu and then select the `Response -> Body Attribute` field. Click on the error that will show up and fill out the modal window as we've done before. Make sure to wrap the `Response -> Body Attribute` with quotation marks, as shown in the screenshot. When the variable is created, your environment should look like this:
4343

44-
![Environment](./assets/environment.png)
44+
![Base environment with added access_token variable](./assets/environment.png)
4545

4646
You will now be able to use this environment variable in all of the endpoints by simply writing `{{access_token}}` in the field that you want to use it in. Coming back to the first example, you can use the access token in the `Authorization` field by writing `Bearer {{access_token}}` and this will be the result:
4747

48-
![Result](./assets/result.png)
48+
![Bearer with access_token env variable](./assets/result.png)
4949

5050
If you try and make the request, you will see that it works just like before, without needing to copy and paste the access token.

0 commit comments

Comments
 (0)