Skip to content

Commit e2046e8

Browse files
Add documentation for the Configuration API, closes #4
Signed-off-by: Xavier Geerinck <[email protected]>
1 parent 3ff006f commit e2046e8

File tree

1 file changed

+50
-1
lines changed
  • daprdocs/content/en/js-sdk-docs/js-server

1 file changed

+50
-1
lines changed

daprdocs/content/en/js-sdk-docs/js-server/_index.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ const serverHost = "127.0.0.1";
168168
const serverPort = "5051";
169169

170170
async function start() {
171-
const server = new DaprServer(serverHost, serverPort, daprHost, daprPort);;
171+
const server = new DaprServer(serverHost, serverPort, daprHost, daprPort);
172172

173173
const bindingName = "my-binding-name";
174174

@@ -185,6 +185,55 @@ start().catch((e) => {
185185

186186
> For a full guide on output bindings visit [How-To: Use bindings]({{< ref howto-bindings.md >}}).
187187
188+
### Configuration API
189+
190+
> 💡 The configuration API is currently only available through gRPC
191+
192+
#### Getting a configuration value
193+
194+
```javascript
195+
import { DaprServer } from "dapr-client";
196+
197+
const daprHost = "127.0.0.1";
198+
const daprPort = "3500";
199+
const serverHost = "127.0.0.1";
200+
const serverPort = "5051";
201+
202+
async function start() {
203+
const client = new DaprClient(daprHost, daprPort, CommunicationProtocolEnum.GRPC);
204+
const config = await client.configuration.get("config-redis", ["myconfigkey1", "myconfigkey2"]);
205+
}
206+
207+
start().catch((e) => {
208+
console.error(e);
209+
process.exit(1);
210+
});
211+
```
212+
213+
#### Subscribing to Key Changes
214+
215+
```javascript
216+
import { DaprServer } from "dapr-client";
217+
218+
const daprHost = "127.0.0.1";
219+
const daprPort = "3500";
220+
const serverHost = "127.0.0.1";
221+
const serverPort = "5051";
222+
223+
async function start() {
224+
const client = new DaprClient(daprHost, daprPort, CommunicationProtocolEnum.GRPC);
225+
await client.configuration.subscribeWithKeys("config-redis", ["myconfigkey1", "myconfigkey2"], () => {
226+
// Received a key update
227+
});
228+
}
229+
230+
start().catch((e) => {
231+
console.error(e);
232+
process.exit(1);
233+
});
234+
```
235+
236+
188237
## Related links
189238

190239
- [JavaScript SDK examples](https://github.com/dapr/js-sdk/tree/master/examples)

0 commit comments

Comments
 (0)