How to add dynamic header in REFIT API .NET

82 views Asked by At

I want to add a dynamic header while making a Refit client call.

This is my refit client code, I am using refit via dependency injection instead of RestService.

[Post("/some-url/")]
Task<ApiResponseMessage<SomeResponseModel>> GetSomething(
    SomeRequestModel request,
    [Header("sessionKey")] string sessionKey,
    CancellationToken cancellationToken = default);

This code does not adds the header, while if I use an delegating handler then it works.

I want to go this way because I need sessionKey in response as well if I go with delegating handler I can't get key in response.

This is how I am calling it

await _serviceApi.GetSomething(command, sessionIdEncryptedValue, ct)

Can anyone tell what am I missing here?

0

There are 0 answers