Skip to main content

Class: DaprClient


PURISTA API / Modules / @purista/dapr-sdk / DaprClient

Class: DaprClient

@purista/dapr-sdk.DaprClient

Hierarchy

Implements

  • HttpEventBridgeClient

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new DaprClient(config): DaprClient

Parameters

NameTypeDescription
configObject-
config.apiPrefix?stringthe prefix to be used if the command is configured as REST api endpoint according to the OpenAPI defintion needs to enableRestApiExpose set to true
config.baseUrlstringthe base url to be used Example typescript const config = { baseUrl: 'http://localhost/api` } // each request will be below http://localhost/api // get('v1/orders') will call http://localhost/api/v1/orders
config.basicAuth?ObjectBasic-Auth information
config.basicAuth.passwordstringBasic-Auth password
config.basicAuth.usernamestringBasic-Auth username
config.bearerToken?stringAuth-Bearer token
config.clientConfig?DaprClientConfig-
config.commandPayloadAsCloudEvent?booleancommand invocations are wrapped in CloudEvent Link https://github.com/cloudevents/spec/tree/v1.0
config.defaultCommandTimeout?numberOverwrite the hardcoded default timeout of command invocations
config.defaultHeaders?Record<string, string>Add your default headers here These headers will be part of every request. They can be overwritten per request option
config.defaultTimeout?numberset global timeout for requests in ms Default ts 30000
config.enableOpentelemetry?booleanenable Opentelemetry tracing. The client will be handled as own ressource.
config.enableRestApiExpose?booleanexpose commands as regular REST endpoints when they are configured as endpoints
config.instanceId?stringThe instance id of the event bridge. If not set, a id will generated each time a instance is created. Use this if there is a need to always have the same instance id.
config.isKeepAlive?booleanIf set to false, the HTTP client will not reuse the same connection for multiple requests. Default is true.
config.logLevel?LogLevelNamethe loglevel if no logger instance is given
config.logger?LoggerA logger instance
config.name?stringName of the client
config.pathPrefix?stringthe prefix to be used for exposing commands as endpoints expecting a event bus message
config.serve(options: { fetch: (request: Request) => unknown ; hostname?: string ; port?: number }) => Server<typeof IncomingMessage, typeof ServerResponse>The serve function is depending on the runtime. - Bun: Bun.serve - Node.js: serve function from additional package @hono/hono-node-server - Deno: serve function from package https://deno.land/std/http/server.ts See https://hono.dev
config.serverHost?stringHost of the server.
config.serverPort?numberPort of the server.
config.spanProcessor?SpanProcessorOpentelemetry span processor
config.subscriptionPayloadAsCloudEvent?booleansubscription invocations are wrapped in CloudEvent Link https://github.com/cloudevents/spec/tree/v1.0

Returns

DaprClient

Inherited from

HttpClient<EventBridgeConfig<DaprEventBridgeConfig>>.constructor

Defined in

core/lib/types/HttpClient/HttpClient.impl.d.ts:26

Properties

baseUrl

baseUrl: URL

Inherited from

HttpClient.baseUrl

Defined in

core/lib/types/HttpClient/HttpClient.impl.d.ts:22


config

config: Object

Type declaration

NameTypeDescription
apiPrefix?stringthe prefix to be used if the command is configured as REST api endpoint according to the OpenAPI defintion needs to enableRestApiExpose set to true
baseUrlstringthe base url to be used Example typescript const config = { baseUrl: 'http://localhost/api` } // each request will be below http://localhost/api // get('v1/orders') will call http://localhost/api/v1/orders
basicAuth?{ password: string ; username: string }Basic-Auth information
basicAuth.passwordstringBasic-Auth password
basicAuth.usernamestringBasic-Auth username
bearerToken?stringAuth-Bearer token
clientConfig?DaprClientConfig-
commandPayloadAsCloudEvent?booleancommand invocations are wrapped in CloudEvent Link https://github.com/cloudevents/spec/tree/v1.0
defaultCommandTimeout?numberOverwrite the hardcoded default timeout of command invocations
defaultHeaders?Record<string, string>Add your default headers here These headers will be part of every request. They can be overwritten per request option
defaultTimeout?numberset global timeout for requests in ms Default ts 30000
enableOpentelemetry?booleanenable Opentelemetry tracing. The client will be handled as own ressource.
enableRestApiExpose?booleanexpose commands as regular REST endpoints when they are configured as endpoints
instanceId?stringThe instance id of the event bridge. If not set, a id will generated each time a instance is created. Use this if there is a need to always have the same instance id.
isKeepAlive?booleanIf set to false, the HTTP client will not reuse the same connection for multiple requests. Default is true.
logLevel?LogLevelNamethe loglevel if no logger instance is given
logger?LoggerA logger instance
name?stringName of the client
pathPrefix?stringthe prefix to be used for exposing commands as endpoints expecting a event bus message
serve(options: { fetch: (request: Request) => unknown ; hostname?: string ; port?: number }) => Server<typeof IncomingMessage, typeof ServerResponse>The serve function is depending on the runtime. - Bun: Bun.serve - Node.js: serve function from additional package @hono/hono-node-server - Deno: serve function from package https://deno.land/std/http/server.ts See https://hono.dev
serverHost?stringHost of the server.
serverPort?numberPort of the server.
spanProcessor?SpanProcessorOpentelemetry span processor
subscriptionPayloadAsCloudEvent?booleansubscription invocations are wrapped in CloudEvent Link https://github.com/cloudevents/spec/tree/v1.0

Inherited from

HttpClient.config

Defined in

core/lib/types/HttpClient/HttpClient.impl.d.ts:20


logger

logger: Logger

Inherited from

HttpClient.logger

Defined in

core/lib/types/HttpClient/HttpClient.impl.d.ts:19


name

name: string

Inherited from

HttpClient.name

Defined in

core/lib/types/HttpClient/HttpClient.impl.d.ts:18


spanProcessor

spanProcessor: undefined | SpanProcessor

Inherited from

HttpClient.spanProcessor

Defined in

core/lib/types/HttpClient/HttpClient.impl.d.ts:23


timeout

timeout: number

Inherited from

HttpClient.timeout

Defined in

core/lib/types/HttpClient/HttpClient.impl.d.ts:21


traceProvider

traceProvider: NodeTracerProvider

Inherited from

HttpClient.traceProvider

Defined in

core/lib/types/HttpClient/HttpClient.impl.d.ts:24

Methods

delete

delete<T>(path, options?, payload?): Promise<T>

DELETE request

Type parameters

Name
T

Parameters

NameType
pathstring
options?HttpClientRequestOptions
payload?unknown

Returns

Promise<T>

Inherited from

HttpClient.delete

Defined in

core/lib/types/HttpClient/HttpClient.impl.d.ts:92


get

get<T>(path, options?): Promise<T>

GET request

Type parameters

Name
T

Parameters

NameType
pathstring
options?HttpClientRequestOptions

Returns

Promise<T>

Inherited from

HttpClient.get

Defined in

core/lib/types/HttpClient/HttpClient.impl.d.ts:64


getApiPathForCommand

getApiPathForCommand(addess, metadata): string

Parameters

NameType
addessEBMessageAddress
metadataObject
metadata.expose{ contentEncodingRequest?: string ; contentEncodingResponse?: string ; contentTypeRequest?: string ; contentTypeResponse?: string ; deprecated?: boolean ; inputPayload?: SchemaObject ; outputPayload?: SchemaObject ; parameter?: SchemaObject } & { http: { method: "GET" | "POST" | "PATCH" | "PUT" | "DELETE" ; openApi?: { additionalStatusCodes?: StatusCode[] ; description: string ; isSecure: boolean ; operationId?: string ; query?: QueryParameter<{}>[] ; summary: string ; tags?: string[] } ; path: string } }

Returns

string

Implementation of

HttpEventBridgeClient.getApiPathForCommand

Defined in

dapr-sdk/src/DaprClient/DaprClient.impl.ts:31open in new window


getInternalPathForCommand

getInternalPathForCommand(address): string

Parameters

NameType
addressEBMessageAddress

Returns

string

Implementation of

HttpEventBridgeClient.getInternalPathForCommand

Defined in

dapr-sdk/src/DaprClient/DaprClient.impl.ts:26open in new window


getInternalPathForSubscription

getInternalPathForSubscription(address): string

Parameters

NameType
addressEBMessageAddress

Returns

string

Implementation of

HttpEventBridgeClient.getInternalPathForSubscription

Defined in

dapr-sdk/src/DaprClient/DaprClient.impl.ts:21open in new window


getTracer

getTracer(): Tracer

Returns open telemetry tracer of this service

Returns

Tracer

Tracer

Inherited from

HttpClient.getTracer

Defined in

core/lib/types/HttpClient/HttpClient.impl.d.ts:32


invoke

invoke(command, headers?, timeout?): Promise<CommandResponse>

Parameters

NameTypeDescription
commandObject-
command.contentEncodingstringcontent encoding of message payload
command.contentTypestringcontent type of message payload
command.correlationIdstringcorrelation id to know which command response referrs to which command
command.eventName?stringevent name for this message
command.idstringglobal unique id of message
command.messageTypeCommand-
command.otp?stringstringified Opentelemetry parent trace id
command.payloadObject-
command.payload.parameterunknown-
command.payload.payloadunknown-
command.principalId?stringprincipal id
command.receiverEBMessageAddress-
command.sender{ serviceName: string; serviceVersion: string; serviceTarget: string; instanceId: string; }-
command.tenantId?stringprincipal id
command.timestampnumbertimestamp of message creation time
command.traceId?stringtrace id of message
headers?Record<string, string>-
timeout?number-

Returns

Promise<CommandResponse>

Implementation of

HttpEventBridgeClient.invoke

Defined in

dapr-sdk/src/DaprClient/DaprClient.impl.ts:36open in new window


isSidecarAvailable

isSidecarAvailable(): Promise<boolean>

Returns

Promise<boolean>

Implementation of

HttpEventBridgeClient.isSidecarAvailable

Defined in

dapr-sdk/src/DaprClient/DaprClient.impl.ts:66open in new window


patch

patch<T>(path, payload, options?): Promise<T>

PATCH request

Type parameters

Name
T

Parameters

NameType
pathstring
payloadunknown
options?HttpClientRequestOptions

Returns

Promise<T>

Inherited from

HttpClient.patch

Defined in

core/lib/types/HttpClient/HttpClient.impl.d.ts:85


post

post<T>(path, payload, options?): Promise<T>

POST request

Type parameters

Name
T

Parameters

NameType
pathstring
payloadunknown
options?HttpClientRequestOptions

Returns

Promise<T>

Inherited from

HttpClient.post

Defined in

core/lib/types/HttpClient/HttpClient.impl.d.ts:71


put

put<T>(path, payload, options?): Promise<T>

PUT request

Type parameters

Name
T

Parameters

NameType
pathstring
payloadunknown
options?HttpClientRequestOptions

Returns

Promise<T>

Inherited from

HttpClient.put

Defined in

core/lib/types/HttpClient/HttpClient.impl.d.ts:78


sendEvent

sendEvent(message, headers?): Promise<void>

Parameters

NameType
messageEBMessage
headers?Record<string, string>

Returns

Promise<void>

Implementation of

HttpEventBridgeClient.sendEvent

Defined in

dapr-sdk/src/DaprClient/DaprClient.impl.ts:51open in new window


setBearerToken

setBearerToken(token): void

Set the bearer token for all following requests.

Parameters

NameTypeDescription
tokenundefined | stringthe bearer token

Returns

void

Inherited from

HttpClient.setBearerToken

Defined in

core/lib/types/HttpClient/HttpClient.impl.d.ts:47


startActiveSpan

startActiveSpan<F>(name, opts, context, fn): Promise<F>

Start a child span for opentelemetry tracking

Type parameters

Name
F

Parameters

NameTypeDescription
namestringname of span
optsSpanOptionsspan options
contextundefined | Contextoptional context
fn(span: Span) => Promise<F>function to be executed within the span

Returns

Promise<F>

return value of fn

Inherited from

HttpClient.startActiveSpan

Defined in

core/lib/types/HttpClient/HttpClient.impl.d.ts:41

Last update:
Contributors: Sebastian Wessel