0

I have API similar to this:

GET /api/token?key={key}

GET /api/data?key={token}
GET /api/data2?key={token}

Before using any other call, I must query the first request and get the token by the fixed key. Then using the thing token, I can make any other query.

Definitely I can define the client as is and in my higher-level logic I can query the token, save it and then pass as an argument, but I'm wondering if it is possible to add transparently, potentially with Polly if needed.

I can create a separate Refit client that can retrieve the token only, and then inject it as a handler to the main client. so whenever I make any call, if I don't have a token, the handler would retrieve a token and pass it.

I'm wondering if there is a more standard way to do so

dr11
  • 5,166
  • 11
  • 35
  • 77
  • 1
    It can be achieved via a `DelegatingHandler` and some helper classes. Here I have showed 3 different ways how can you achieve it with refresh capability: https://stackoverflow.com/questions/59833373 – Peter Csala Aug 29 '23 at 07:36
  • Does this answer your question? [Refresh Token using Polly with Named Client](https://stackoverflow.com/questions/59833373/refresh-token-using-polly-with-named-client) – Peter Csala Aug 30 '23 at 07:20

0 Answers0