Vscode-restclient: Set variable value from response

Created on 3 Jan 2021  路  5Comments  路  Source: Huachao/vscode-restclient

Example:
@accessToken variable is something that always requires adding a new token whenever hit the login or auth API.

Most helpful comment

Let me brief.

Suppose I have a variable name accessToken, and I am putting this variable in every request which require authorization.
e.g. user/profile require token in header as a 'Bearer {{accessToken}}'

Currently, we assign value in accesToken manually, But I want to assign it dynamically from user/login API response which returns token, I want to assign the same token in accessToken variable.
So whenever I will hit user/login API it will always set the token to accessToken variable.

This will save time for entering tokens every time manually.
and it can be used in various scenarios.

All 5 comments

@hidaytrahman I didn't quite understand it, could you please explain it for me with more details?

@hidaytrahman check this link to learn how to use request variables

Let me brief.

Suppose I have a variable name accessToken, and I am putting this variable in every request which require authorization.
e.g. user/profile require token in header as a 'Bearer {{accessToken}}'

Currently, we assign value in accesToken manually, But I want to assign it dynamically from user/login API response which returns token, I want to assign the same token in accessToken variable.
So whenever I will hit user/login API it will always set the token to accessToken variable.

This will save time for entering tokens every time manually.
and it can be used in various scenarios.

We need a hook before sending a http request, we should be able to get new token assign it to accessToken variable. Right now its a manual process. Take the case of switching env, I have to set the value of accessToken again manually. I know I can set a constant accessToken for each env, but odic tokens have sliding expiration. Postman allows scripts or hooks the gets executed before making http calls. And these script/hooks also works off the env variables

@hidaytrahman You can do that using request variables.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

abenedykt picture abenedykt  路  18Comments

olivier-voutat picture olivier-voutat  路  23Comments

lldata picture lldata  路  13Comments

akalcik picture akalcik  路  16Comments

OzgurDogan picture OzgurDogan  路  13Comments