AnWeber / httpbook

Quickly and easily send REST, Soap, GraphQL, GRPC, MQTT and WebSocket requests directly within Visual Studio Code
https://httpyac.github.io/
MIT License
58 stars 4 forks source link

Is there a problem with @ref and @forceRef ? #70

Closed dlucazeau closed 1 year ago

dlucazeau commented 1 year ago

Hello Andreas,

I think so.

I have a cell "# @name login" that is used by an accessToken cell in the same httpbook, "# @name accessToken"; itself used by a cell in another httpbook. Whether the references are cascaded by @forceRef or by @ref - after the first two cells are executed, my token is still the one from before and becomes invalid over time. I have to close VSCode and reopen it so that the token being used is the correct one. I tried to clear the cache but it doesn't change anything.

Thank you again for this great work which helps me a lot.

AnWeber commented 1 year ago

I am just trying to understand the structure. I put this example together, I noticed that httpbook does not currently populate the history. Therefore I use vscode-httpyac for my gif. But according to the output it seems to work in httpbook.

login.http


# @name login
GET https://httpbin.org/anything?id={{$guid}} HTTP/1.1

@name accessToken

@forceRef login

POST https://httpbin.org/anything HTTP/1.1 {{login.args.id}}

@name accessToken_no_new_login

@ref login

POST https://httpbin.org/anything HTTP/1.1 {{login.args.id}}

> request.http

@import ./login.http

Always Execute all Requests

@forceRef accessToken

POST https://httpbin.org/anything HTTP/1.1 {{accessToken.data}}

Only Call AccessToken but no new Login Request

@import ./id.http

@forceRef accessToken_no_new_login

POST https://httpbin.org/anything HTTP/1.1 {{accessToken.data}}

No Update of AccessToken after First Request

@import ./id.http

@ref accessToken_no_new_login

POST https://httpbin.org/anything HTTP/1.1 {{accessToken.data}}



- Request `Always Execute all Requests` always calls accessToken which `@forceRef`/ calls login. I get always a new guid => seems correct
- Request ` Only Call AccessToken but no new Login Request` always calls accessToken which only `@ref` login. Login is only called on first request => I get only once my guid, but I see a request in Output/history for accessToken 
- Request `No Update of AccessToken after First Request` does only `@ref` accessToken => only on first request the complete request chain is used and after that all calls a prevented.

![forceref](https://user-images.githubusercontent.com/13434739/188223579-9798017e-1534-415e-b3e7-e30857196d8b.gif)

The difference between `@ref` and `@forceRef` is only whether the variable `login` or `accessToken` are present. [If `@ref` and the variable is present](https://github.com/AnWeber/httpyac/blob/main/src/plugins/core/metaData/refMetaDataHandler.ts#L48), I would not re-execute the request. But this also only means that I consider this for the current `@ref` request so a behavior `@forceRefDeep` I have not considered. 

Another workaround would be to run command `httpyac.reset` as this will clear all variables.