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

Refactor service invocation API and add examples

Open shubham1172 opened this issue 2 years ago • 1 comments

The current service invocation API is confusing. For example, the GRPC invocation requires a HTTP verb to be passed.

From https://github.com/dapr/js-sdk/blob/master/test/e2e/main.grpc.test.ts

it('should be able to listen and invoke a service with GET', async () => {
      const mock = jest.fn(async (_data: object) => ({ hello: 'world' }));

      await server.invoker.listen('hello-world', mock, { method: HttpMethod.GET });
      const res = await client.invoker.invoke(daprAppId, 'hello-world', HttpMethod.GET);

      // Delay a bit for event to arrive
      // await new Promise((resolve, reject) => setTimeout(resolve, 250));

      expect(mock.mock.calls.length).toBe(1);
      expect(JSON.stringify(res)).toEqual(`{"hello":"world"}`);
    });

This issue is to fix the interfaces and relevant implementations. Also update examples to show the same.

shubham1172 avatar Mar 22 '22 18:03 shubham1172

This issue has been automatically marked as stale because it has not had activity in the last 60 days. It will be closed in the next 7 days unless it is tagged (pinned, good first issue, help wanted or triaged/resolved) or other activity occurs. Thank you for your contributions.

dapr-bot avatar May 28 '22 15:05 dapr-bot