js-sdk icon indicating copy to clipboard operation
js-sdk copied to clipboard

Support customized header for invoker

Open Halomaple opened this issue 4 years ago • 3 comments

In many cases we need passing some params like X-UserId from web to backend in HTTP header, but current implementation of js-sdk is blocking the header. See src/implementation/Client/HTTPClient/invoker.ts line 31-36:

    if (method !== HttpMethod.GET) {
      // @ts-ignore
      fetchOptions.headers = {
        'Content-Type': 'application/json'
      };
    }

So I wonder whether we can add new param named header in function invoke to support this? Like async invoke(appId: string, methodName: string, method: HttpMethod = HttpMethod.GET, data: object = {}, header = {}): Promise<object> {}

Halomaple avatar Mar 22 '22 05:03 Halomaple

I support this request. It is something already supported by dotnet-sdk https://github.com/dapr/dotnet-sdk/issues/396

shubham1172 avatar Mar 22 '22 11:03 shubham1172

I did a fork and implemented it. That is 6 lines of code....could submit a PR eventually.

pnocera avatar May 04 '22 09:05 pnocera

@pnocera that's great, feel free to raise a PR. Thank you for helping out!

shubham1172 avatar May 04 '22 10:05 shubham1172