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

Update DaprClient and DaprServer API for easier usage

Open shubham1172 opened this issue 2 years ago • 1 comments

Describe the proposal

The current DaprClient API looks like this:

 constructor(
    daprHost?: string
    , daprPort?: string
    , communicationProtocol: CommunicationProtocolEnum = CommunicationProtocolEnum.HTTP
    , options: DaprClientOptions = {},
  )

Since typescript does not have support for named parameters, skipping one parameter and adding the next one will result in something like this on the consumer end:

var clientOptions = {logger: {level: LogLevel.Debug}}
const client = new DaprClient(
    daprHost,
    undefined, // default is process.env.DAPR_HTTP_PORT ?? 3500
    undefined, // default is CommunicationProtocolEnum.HTTP
    clientOptions);

The proposal is to move to a more friendlier DaprClient API:

 constructor(DaprClientOptions)
// ...
export type DaprClientOptions = {
  daprHost?: string;
  daprPort?: string;
  communicationProtocol: CommunicationProtocolEnum;
  isKeepAlive?: boolean;
  logger?: LoggerOptions;
}

This will allow consumers to instantiate DaprClient as follows:

const client = new DaprClient({
    daprHost:daprHost,
    logger:loggerOptions});

Similar exercise proposed for DaprServer.

shubham1172 avatar Jun 09 '22 14:06 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 Aug 08 '22 14:08 dapr-bot

Hi @shubham1172 changes should be reflect in test cases to ?

salmankhan-prs avatar Nov 27 '22 06:11 salmankhan-prs

Hi @shubham1172 changes should be reflect in test cases to ?

Yes, this proposal requires a broader discussion before any implementation, feel free to add them to this thread/join our community calls and talk about it.

shubham1172 avatar Nov 27 '22 15:11 shubham1172

Closing in favor of #442 and #444

XavierGeerinck avatar Jan 17 '23 16:01 XavierGeerinck