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