PURISTA API / Modules / @purista/dapr-sdk / DaprClient
Class: DaprClient
@purista/dapr-sdk.DaprClient
The HttpEventBridgeClient connects the HTTPEventBridge with the sidecar service. This client is responsible for the communication to the sidecar service.
Hierarchy
HttpClient
<EventBridgeConfig
<DaprEventBridgeConfig
>>↳
DaprClient
Implements
Table of contents
Constructors
Properties
Methods
- delete
- execute
- get
- getApiPathForCommand
- getInternalPathForCommand
- getInternalPathForSubscription
- getTracer
- getUrlAndHeader
- invoke
- isSidecarAvailable
- patch
- post
- put
- sendEvent
- setBearerToken
- startActiveSpan
Constructors
constructor
• new DaprClient(config
): DaprClient
Parameters
Name | Type | Description |
---|---|---|
config | Object | - |
config.apiPrefix? | string | the prefix to be used if the command is configured as REST api endpoint according to the OpenAPI defintion needs to enableRestApiExpose set to true Default ts /api |
config.baseUrl | string | the 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? | Object | Basic-Auth information |
config.basicAuth.password | string | Basic-Auth password |
config.basicAuth.username | string | Basic-Auth username |
config.bearerToken? | string | Auth-Bearer token |
config.clientConfig? | DaprClientConfig | - |
config.commandPayloadAsCloudEvent? | boolean | command invocations are wrapped in CloudEvent Link https://github.com/cloudevents/spec/tree/v1.0 Default ts false |
config.defaultCommandTimeout? | number | Overwrite 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? | number | set global timeout for requests in ms Default ts 30000 |
config.enableHttpCompression? | boolean | enable HTTP compression in web server Default ts true |
config.enableOpentelemetry? | boolean | enable Opentelemetry tracing. The client will be handled as own ressource. |
config.enableRestApiExpose? | boolean | expose commands as regular REST endpoints when they are configured as endpoints Default ts true |
config.instanceId? | string | The 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? | boolean | If set to false, the HTTP client will not reuse the same connection for multiple requests. Default is true. |
config.logLevel? | LogLevelName | the loglevel if no logger instance is given |
config.logger? | Logger | A logger instance |
config.name? | string | Name of the client |
config.pathPrefix? | string | the prefix to be used for exposing commands as endpoints expecting a event bus message Default ts purista |
config.serve | (options : { fetch : (request : Request ) => unknown ; hostname? : string ; port? : number }) => Server <typeof IncomingMessage , typeof ServerResponse > | Http2Server | Http2SecureServer | 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? | string | Host of the server. Default ts 127.0.0.1 |
config.serverPort? | number | Port of the server. Default ts 8080 |
config.spanProcessor? | SpanProcessor | Opentelemetry span processor |
config.subscriptionPayloadAsCloudEvent? | boolean | subscription invocations are wrapped in CloudEvent Link https://github.com/cloudevents/spec/tree/v1.0 Default ts false |
config.traceId? | string | Custom trace Id |
Returns
Inherited from
Defined in
core/dist/commonjs/HttpClient/HttpClient.impl.d.ts:28
Properties
auth
• Protected
auth: AuthCredentials
Inherited from
Defined in
core/dist/commonjs/HttpClient/HttpClient.impl.d.ts:27
baseUrl
• baseUrl: URL
Inherited from
Defined in
core/dist/commonjs/HttpClient/HttpClient.impl.d.ts:24
config
• config: Object
Type declaration
Name | Type | Description |
---|---|---|
apiPrefix? | string | the prefix to be used if the command is configured as REST api endpoint according to the OpenAPI defintion needs to enableRestApiExpose set to true Default ts /api |
baseUrl | string | the 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.password | string | Basic-Auth password |
basicAuth.username | string | Basic-Auth username |
bearerToken? | string | Auth-Bearer token |
clientConfig? | DaprClientConfig | - |
commandPayloadAsCloudEvent? | boolean | command invocations are wrapped in CloudEvent Link https://github.com/cloudevents/spec/tree/v1.0 Default ts false |
defaultCommandTimeout? | number | Overwrite 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? | number | set global timeout for requests in ms Default ts 30000 |
enableHttpCompression? | boolean | enable HTTP compression in web server Default ts true |
enableOpentelemetry? | boolean | enable Opentelemetry tracing. The client will be handled as own ressource. |
enableRestApiExpose? | boolean | expose commands as regular REST endpoints when they are configured as endpoints Default ts true |
instanceId? | string | The 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? | boolean | If set to false, the HTTP client will not reuse the same connection for multiple requests. Default is true. |
logLevel? | LogLevelName | the loglevel if no logger instance is given |
logger? | Logger | A logger instance |
name? | string | Name of the client |
pathPrefix? | string | the prefix to be used for exposing commands as endpoints expecting a event bus message Default ts purista |
serve | (options : { fetch : (request : Request ) => unknown ; hostname? : string ; port? : number }) => Server <typeof IncomingMessage , typeof ServerResponse > | Http2Server | Http2SecureServer | 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? | string | Host of the server. Default ts 127.0.0.1 |
serverPort? | number | Port of the server. Default ts 8080 |
spanProcessor? | SpanProcessor | Opentelemetry span processor |
subscriptionPayloadAsCloudEvent? | boolean | subscription invocations are wrapped in CloudEvent Link https://github.com/cloudevents/spec/tree/v1.0 Default ts false |
traceId? | string | Custom trace Id |
Inherited from
Defined in
core/dist/commonjs/HttpClient/HttpClient.impl.d.ts:22
logger
• logger: Logger
Inherited from
Defined in
core/dist/commonjs/HttpClient/HttpClient.impl.d.ts:21
name
• name: string
Inherited from
Defined in
core/dist/commonjs/HttpClient/HttpClient.impl.d.ts:20
spanProcessor
• spanProcessor: undefined
| SpanProcessor
Inherited from
Defined in
core/dist/commonjs/HttpClient/HttpClient.impl.d.ts:25
timeout
• timeout: number
Inherited from
Defined in
core/dist/commonjs/HttpClient/HttpClient.impl.d.ts:23
traceProvider
• traceProvider: NodeTracerProvider
Inherited from
Defined in
core/dist/commonjs/HttpClient/HttpClient.impl.d.ts:26
Methods
delete
▸ delete<T
>(path
, options?
, payload?
): Promise
<T
>
DELETE request
Type parameters
Name |
---|
T |
Parameters
Name | Type |
---|---|
path | string |
options? | HttpClientRequestOptions |
payload? | unknown |
Returns
Promise
<T
>
Inherited from
Defined in
core/dist/commonjs/HttpClient/HttpClient.impl.d.ts:97
execute
▸ execute(method
, path
, options?
, payload?
): Promise
<any
>
Helper method
Parameters
Name | Type |
---|---|
method | string |
path | string |
options? | HttpClientRequestOptions |
payload? | unknown |
Returns
Promise
<any
>
Throws
UnhandledError
Inherited from
Defined in
core/dist/commonjs/HttpClient/HttpClient.impl.d.ts:62
get
▸ get<T
>(path
, options?
): Promise
<T
>
GET request
Type parameters
Name |
---|
T |
Parameters
Name | Type |
---|---|
path | string |
options? | HttpClientRequestOptions |
Returns
Promise
<T
>
Inherited from
Defined in
core/dist/commonjs/HttpClient/HttpClient.impl.d.ts:69
getApiPathForCommand
▸ getApiPathForCommand(addess
, metadata
): string
Generate the url path of the command based on the command builder exposeAsHttpEndpoint
settings. This url is a POST endpoint and expects the payload and parameter as defined for exposing.
Parameters
Name | Type |
---|---|
addess | EBMessageAddress |
metadata | Object |
metadata.expose | { contentEncodingRequest? : string ; contentEncodingResponse? : string ; contentTypeRequest? : string ; contentTypeResponse? : string ; deprecated? : boolean ; inputPayload? : SchemaObject ; outputPayload? : SchemaObject ; parameter? : SchemaObject } & { http : { method : "POST" | "GET" | "PATCH" | "PUT" | "DELETE" ; openApi? : { additionalStatusCodes? : StatusCode [] ; description : string ; isSecure : boolean ; operationId? : string ; query? : QueryParameter <{}>[] ; summary : string ; tags? : string [] } ; path : string } } |
Returns
string
url path of endpoint
Implementation of
HttpEventBridgeClient.getApiPathForCommand
Defined in
dapr-sdk/src/DaprClient/DaprClient.impl.ts:28
getInternalPathForCommand
▸ getInternalPathForCommand(address
): string
Generate the url path of the command. This url is a POST endpoint and expects a command message as payload
Parameters
Name | Type |
---|---|
address | EBMessageAddress |
Returns
string
url path of endpoint
Implementation of
HttpEventBridgeClient.getInternalPathForCommand
Defined in
dapr-sdk/src/DaprClient/DaprClient.impl.ts:23
getInternalPathForSubscription
▸ getInternalPathForSubscription(address
): string
Generate the url path of the subscription. This url is a POST endpoint. The expected payload is a EBMessage or an CloudEvent with an EBMessage as data depending on config settings
Parameters
Name | Type |
---|---|
address | EBMessageAddress |
Returns
string
url path of endpoint
Implementation of
HttpEventBridgeClient.getInternalPathForSubscription
Defined in
dapr-sdk/src/DaprClient/DaprClient.impl.ts:18
getTracer
▸ getTracer(): Tracer
Returns open telemetry tracer of this service
Returns
Tracer
Tracer
Inherited from
Defined in
core/dist/commonjs/HttpClient/HttpClient.impl.d.ts:34
getUrlAndHeader
▸ getUrlAndHeader(path
, options?
): Object
Parameters
Name | Type |
---|---|
path | string |
options? | HttpClientRequestOptions |
Returns
Object
Name | Type |
---|---|
headers | Record <string , string > |
url | URL |
Inherited from
Defined in
core/dist/commonjs/HttpClient/HttpClient.impl.d.ts:44
invoke
▸ invoke(command
, headers?
, timeout?
): Promise
<CommandResponse
>
Invoke a command
Parameters
Name | Type | Description |
---|---|---|
command | Object | Command |
command.contentEncoding | string | content encoding of message payload |
command.contentType | string | content type of message payload |
command.correlationId | string | correlation id to know which command response referrs to which command |
command.eventName? | string | event name for this message |
command.id | string | global unique id of message |
command.messageType | Command | - |
command.otp? | string | stringified Opentelemetry parent trace id |
command.payload | Object | - |
command.payload.parameter | unknown | - |
command.payload.payload | unknown | - |
command.principalId? | string | principal id |
command.receiver | EBMessageAddress | - |
command.sender | Object | - |
command.sender.instanceId | string | instance id of eventbridge |
command.sender.serviceName | string | the name of the service |
command.sender.serviceTarget | string | the name of the command or subscription |
command.sender.serviceVersion | string | the version of the service |
command.tenantId? | string | principal id |
command.timestamp | number | timestamp of message creation time |
command.traceId? | string | trace id of message |
headers? | Record <string , string > | optional HTTP header |
timeout? | number | the command timeout |
Returns
Promise
<CommandResponse
>
Implementation of
Defined in
dapr-sdk/src/DaprClient/DaprClient.impl.ts:33
isSidecarAvailable
▸ isSidecarAvailable(): Promise
<boolean
>
Checks if the sidecar container is available to be able to send events and invoke commands
Returns
Promise
<boolean
>
boolean
Implementation of
HttpEventBridgeClient.isSidecarAvailable
Defined in
dapr-sdk/src/DaprClient/DaprClient.impl.ts:63
patch
▸ patch<T
>(path
, payload
, options?
): Promise
<T
>
PATCH request
Type parameters
Name |
---|
T |
Parameters
Name | Type |
---|---|
path | string |
payload | unknown |
options? | HttpClientRequestOptions |
Returns
Promise
<T
>
Inherited from
Defined in
core/dist/commonjs/HttpClient/HttpClient.impl.d.ts:90
post
▸ post<T
>(path
, payload
, options?
): Promise
<T
>
POST request
Type parameters
Name |
---|
T |
Parameters
Name | Type |
---|---|
path | string |
payload | unknown |
options? | HttpClientRequestOptions |
Returns
Promise
<T
>
Inherited from
Defined in
core/dist/commonjs/HttpClient/HttpClient.impl.d.ts:76
put
▸ put<T
>(path
, payload
, options?
): Promise
<T
>
PUT request
Type parameters
Name |
---|
T |
Parameters
Name | Type |
---|---|
path | string |
payload | unknown |
options? | HttpClientRequestOptions |
Returns
Promise
<T
>
Inherited from
Defined in
core/dist/commonjs/HttpClient/HttpClient.impl.d.ts:83
sendEvent
▸ sendEvent(message
, headers?
): Promise
<void
>
Send a EBMessage as event to the underlaying message infrastructure.
Parameters
Name | Type |
---|---|
message | EBMessage |
headers? | Record <string , string > |
Returns
Promise
<void
>
Implementation of
HttpEventBridgeClient.sendEvent
Defined in
dapr-sdk/src/DaprClient/DaprClient.impl.ts:48
setBearerToken
▸ setBearerToken(token
): void
Set the bearer token for all following requests.
Parameters
Name | Type | Description |
---|---|---|
token | undefined | string | the bearer token |
Returns
void
Inherited from
Defined in
core/dist/commonjs/HttpClient/HttpClient.impl.d.ts:52
startActiveSpan
▸ startActiveSpan<F
>(name
, opts
, context
, fn
): Promise
<F
>
Start a child span for opentelemetry tracking
Type parameters
Name |
---|
F |
Parameters
Name | Type | Description |
---|---|---|
name | string | name of span |
opts | SpanOptions | span options |
context | undefined | Context | optional context |
fn | (span : Span ) => Promise <F > | function to be executed within the span |
Returns
Promise
<F
>
return value of fn
Inherited from
Defined in
core/dist/commonjs/HttpClient/HttpClient.impl.d.ts:43