Skip to content

Refactor service invocation API and add examples #220

@shubham1172

Description

@shubham1172

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.

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Assigned

Relationships

None yet

Development

No branches or pull requests

Issue actions