@@ -19,8 +19,7 @@ Install the SDK with npm:
19
19
npm i @dapr/js-sdk
20
20
```
21
21
22
- Import the libraries for the the given protocol:
23
-
22
+ Import the libraries for the the given protocol:
24
23
``` javascript
25
24
const daprHost = " 127.0.0.1" ; // Dapr Sidecar Host
26
25
const daprPort = " 50050" ; // Dapr Sidecar Port of this Example Server
@@ -39,6 +38,13 @@ const server = new DaprServer(serverHost, serverPort, daprHost, daprPort, Commun
39
38
const client = new DaprClient (daprHost, daprPort, CommunicationProtocolEnum .GRPC );
40
39
```
41
40
41
+ ##### Client Library
42
+ A library that provides methods for how an application communicates with the Dapr sidecar.
43
+
44
+ ##### Server Library
45
+ A library for how an application registers bindings / routes with Dapr. The ` startServer ` method is used to start the server and bind the routes.
46
+
47
+
42
48
## Building blocks
43
49
44
50
The JavaScript SDK allows you to interface with all of the [ Dapr building blocks] ({{< ref building-blocks >}}).
@@ -61,7 +67,7 @@ async function start() {
61
67
return { hello: " world received from POST" };
62
68
}, { method: HttpMethod .POST });
63
69
64
- // GET listener
70
+ // GET listener
65
71
await server .invoker .listen (" hello-world" , async () => {
66
72
return { hello: " world received from GET" };
67
73
}, { method: HttpMethod .GET });
@@ -74,16 +80,16 @@ async function start() {
74
80
const serviceAppId = " my-dapr-app-id" ;
75
81
const serviceMethod = " say-hello" ;
76
82
77
- // POST Request
83
+ // POST Request
78
84
const response = await client .invoker .invoke (serviceAppId , serviceMethod , HttpMethod .POST , { hello: " world" });
79
85
80
- // GET Request
86
+ // GET Request
81
87
const response = await client .invoker .invoke (serviceAppId , serviceMethod , HttpMethod .GET );
82
88
}
83
89
```
84
90
- For a full guide on service invocation visit [ How-To: Invoke a service] ({{< ref howto-invoke-discover-services.md >}}).
85
91
86
- ### Save & get application state
92
+ ### Save, get and delete application state
87
93
88
94
``` javascript
89
95
import { DaprClient } from " @dapr/js-sdk" ;
@@ -96,25 +102,25 @@ async function start() {
96
102
97
103
const serviceStoreName = " my-dapr-state-store" ;
98
104
99
- // Save state
105
+ // Save State
100
106
const response = await client .state .save (serviceStoreName, [
101
107
{
102
108
key: " first-key-name" ,
103
- value: " Hello "
109
+ value: " hello "
104
110
},
105
111
{
106
112
key: " second-key-name" ,
107
- value: " World! "
113
+ value: " world "
108
114
}
109
115
]);
110
116
111
- // Get State
117
+ // Get State
112
118
const response = await client .state .get (serviceStoreName, " first-key-name" );
113
119
114
- // Get Bulk State
120
+ // Get Bulk State
115
121
const response = await client .state .getBulk (serviceStoreName, [" first-key-name" , " second-key-name" ]);
116
122
117
- // Delete State
123
+ // Delete State
118
124
const response = await client .state .delete (serviceStoreName, " first-key-name" );
119
125
}
120
126
```
@@ -137,7 +143,8 @@ async function start() {
137
143
const topic = " topic-a" ;
138
144
const message = { hello: " world" }
139
145
140
- const response = await client .pubsub .publish (pubSubName- redis, topic, message);
146
+ // Publish Message to Topic
147
+ const response = await client .pubsub .publish (pubSubName, topic, message);
141
148
}
142
149
```
143
150
@@ -155,6 +162,7 @@ async function start() {
155
162
const pubSubName = " my-dapr-pubsub" ;
156
163
const topic = " topic-a" ;
157
164
165
+ // Configure Subscriber for a Topic
158
166
await server .pubsub .subscribe (pubSubName, topic, async (data : any ) => console .log (` Got Data: ${ JSON .stringify (data)} ` ));
159
167
160
168
await server .startServer ();
@@ -228,7 +236,6 @@ async function start() {
228
236
- For a full guide on secrets visit [ How-To: Retrieve secrets] ({{< ref howto-secrets.md >}}).
229
237
230
238
### Actors
231
- An actor is an isolated, independent unit of compute and state with single-threaded execution. Dapr provides an actor implementation based on the [ Virtual Actor pattern] ( https://www.microsoft.com/en-us/research/project/orleans-virtual-actors/ ) , which provides a single-threaded programming model and where actors are garbage collected when not in use. With Dapr's implementaiton, you write your Dapr actors according to the Actor model, and Dapr leverages the scalability and reliability that the underlying platform provides.
232
239
233
240
``` javascript
234
241
```
0 commit comments