Skip to content

Commit

Permalink
Upmerge of v1.7 into v1.8 20220518 (#2446)
Browse files Browse the repository at this point in the history
* fix code snippet typo and grammar pass

Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com>

* fix parameter typo and grammar pass

Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com>

* Fix CLI command typo

Fix CLI certificate renewal command typo

Signed-off-by: Bernd Verst <4535280+berndverst@users.noreply.github.com>

* Fixes state-store-ttl Python example (#2352)

* Update state-store-ttl.md

Add comma so the metadata value is a tuple of tuple, otherwise Python collapses it to just being an ordinary tuple.

Signed-off-by: Bernd Verst <4535280+berndverst@users.noreply.github.com>

* Update pubsub-raw.md

Signed-off-by: Bernd Verst <4535280+berndverst@users.noreply.github.com>

Co-authored-by: Mark Fussell <markfussell@gmail.com>

* Fix go quickstart port (#2360)

* fix go quickstart port

Signed-off-by: yaron2 <schneider.yaron@live.com>

* fix pub/sub port also

Signed-off-by: yaron2 <schneider.yaron@live.com>

* Fixes wrong working directory for dotnet state management sample (#2359)

* Wrong working directory for .Net state management sample

The working directory for .NET is pointing to `pub_sub` but it should be `state_management`.

Signed-off-by: Stephane Lapointe <stephane.lap@outlook.com>

* Removing the word "publisher" which was also unneed

Co-authored-by: Mark Fussell <markfussell@gmail.com>

* add new dapr init flags and examples to docs

Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com>

* quick save

Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com>

* [state management] Update docs around transactional operations (#2372)

* clarify transactional operations in docs

Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com>

* Added some more details for clarity

* updates per Mark

Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com>

* remove en from link

Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com>

* ignore links attempt

Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com>

Co-authored-by: Mark Fussell <markfussell@gmail.com>

* Fixed typo in security concept doc (#2374)

Signed-off-by: moreyhat <moreyhat@gmail.com>

Co-authored-by: Yaron Schneider <schneider.yaron@live.com>

* Fix curl example

`\` is missing for some curl examples.

Signed-off-by: zhangchao <zchao9100@gmail.com>

* Update metrics-overview.md

* replace zip file; update url (#2386)

Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com>

* Update to version to 1.7.1 (#2388)

Signed-off-by: Nick Greenfield <nigreenf@microsoft.com>

* typo fix (#2384)

Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com>

Co-authored-by: Mark Fussell <markfussell@gmail.com>

* update building_blocks.png (#2387)

Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com>

Co-authored-by: Mark Fussell <markfussell@gmail.com>

* Update dapr runtime version to 1.7.2

Signed-off-by: Nick Greenfield <nigreenf@microsoft.com>

* Remove "quickstart" references from tutorial (#2383)

* remove quickstart references

Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com>

* Update daprdocs/content/en/getting-started/tutorials/get-started-component.md

* Update daprdocs/content/en/getting-started/tutorials/get-started-component.md

Co-authored-by: Mark Fussell <markfussell@gmail.com>

* sentry isn't installed by default in self-hosted mode (#2366)

* sentry isn't installed by default in self-hosted mode

Fixes: #2365

Signed-off-by: Doug Davis <dug@microsoft.com>

* Update daprdocs/content/en/concepts/dapr-services/sentry.md

Co-authored-by: greenie-msft <56556602+greenie-msft@users.noreply.github.com>
Co-authored-by: Mark Fussell <markfussell@gmail.com>

* Bump nanoid from 3.1.23 to 3.3.2 in /daprdocs (#2348)

Bumps [nanoid](https://github.com/ai/nanoid) from 3.1.23 to 3.3.2.
- [Release notes](https://github.com/ai/nanoid/releases)
- [Changelog](https://github.com/ai/nanoid/blob/main/CHANGELOG.md)
- [Commits](ai/nanoid@3.1.23...3.3.2)

---
updated-dependencies:
- dependency-name: nanoid
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: greenie-msft <56556602+greenie-msft@users.noreply.github.com>
Co-authored-by: Mark Fussell <markfussell@gmail.com>

* update JS submodule

Signed-off-by: Nick Greenfield <nigreenf@microsoft.com>

* [Dapr API] Extend example to include delete state (#2377)

* extend dapr api example

Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com>

* remove extra #

Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com>

* quote urls

Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com>

* ignore links

Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com>

* remove transactional and bulk get

Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com>

* update intro to only one object

Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com>

* Update daprdocs/content/en/getting-started/get-started-api.md

Co-authored-by: Mark Fussell <markfussell@gmail.com>

* Update daprdocs/content/en/getting-started/get-started-api.md

Co-authored-by: Mark Fussell <markfussell@gmail.com>

* Update daprdocs/content/en/getting-started/get-started-api.md

Co-authored-by: Mark Fussell <markfussell@gmail.com>

* Update daprdocs/content/en/getting-started/get-started-api.md

Co-authored-by: Mark Fussell <markfussell@gmail.com>

* Update daprdocs/content/en/getting-started/get-started-api.md

Co-authored-by: Mark Fussell <markfussell@gmail.com>

* Update daprdocs/content/en/getting-started/get-started-api.md

Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com>

Co-authored-by: Mark Fussell <markfussell@gmail.com>

Co-authored-by: Mark Fussell <markfussell@gmail.com>

* Fix TTL example for Python (#2394)

Signed-off-by: Bernd Verst <4535280+berndverst@users.noreply.github.com>

* Fix config yaml w.r.t. name and namespace (#2397)

The config sample yaml used the wrong namespace and while in there I decided to
mention the name of the config instead of just its namespace since the two
are so similar, I didn't want people to think one was a typo.

And the monitoring sample had a typo.

Signed-off-by: Doug Davis <dug@microsoft.com>

* [quickstarts] fix port typo in pubsub and service invo (#2369)

* fix typo in js command

Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com>

* check commands in other quickstarts

Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com>

Co-authored-by: Mark Fussell <markfussell@gmail.com>

* update kubernetes overview to explain where annotations should actually go to (#2400)

Signed-off-by: Thorsten Hans <thorsten.hans@gmail.com>

Co-authored-by: Yaron Schneider <schneider.yaron@live.com>

* Add profile-port to env variables table (#2402)

* add profile-port to env variables table

Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com>

* fix link

Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com>

Co-authored-by: Mark Fussell <markfussell@gmail.com>

* [secrets and actors api reference docs] error code fixes (#2356)

* error code fixes

Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com>

* reverting changes to secrets api

Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com>

Co-authored-by: Mark Fussell <markfussell@gmail.com>

* update presentation

Signed-off-by: msfussell <markfussell@gmail.com>

* add missing upgrade step for 1.7 (#2423)

Signed-off-by: yaron2 <schneider.yaron@live.com>

* update presentation (#2415)

Signed-off-by: msfussell <markfussell@gmail.com>

Co-authored-by: greenie-msft <56556602+greenie-msft@users.noreply.github.com>

* new deck

Signed-off-by: msfussell <markfussell@gmail.com>

* Fixes in howto-bindings: (#2416)

- JS and curl samples were sending data as objects but sample apps expected ints
- Improved JS sample to correctly handle async code and make it more readable
- Fixed indentation in .NET code
- JavaScript has uppercased S

Signed-off-by: Alessandro Segala (ItalyPaleAle) <43508+ItalyPaleAle@users.noreply.github.com>

Co-authored-by: Mark Fussell <markfussell@gmail.com>

* API tokens do not need to be JWT's (#2332)

* API tokens do not need to be JWT's

Signed-off-by: Alessandro (Ale) Segala <43508+ItalyPaleAle@users.noreply.github.com>

* Updated app-api-token

Signed-off-by: GitHub <noreply@github.com>

Co-authored-by: Mark Fussell <markfussell@gmail.com>

* message for restarting the dapr-enabled pods (#2399)

* message for restarting the dapr-enabled pods

Signed-off-by: Pravin Pushkar <ppushkar@microsoft.com>

* Addressed review comments

Signed-off-by: Pravin Pushkar <ppushkar@microsoft.com>

Co-authored-by: Mark Fussell <markfussell@gmail.com>

* fix kafka pubsub example config (#2429)

Signed-off-by: zhangchao <zchao9100@gmail.com>

* update otel collector version to 0.50.0 (#2434)

Signed-off-by: fabistb <fabian0401@online.de>

* Fixing URL bug in AWS name (#2439)

Signed-off-by: msfussell <markfussell@gmail.com>

* Update runtime version to 1.7.3

Signed-off-by: Nick Greenfield <nigreenf@microsoft.com>

* correct configuration.program in launch.json

Signed-off-by: Jack Liu shurui <jackliusr@gmail.com>

Co-authored-by: Hannah Hunter <hannahhunter@microsoft.com>
Co-authored-by: Bernd Verst <4535280+berndverst@users.noreply.github.com>
Co-authored-by: Mark Fussell <markfussell@gmail.com>
Co-authored-by: Yaron Schneider <schneider.yaron@live.com>
Co-authored-by: Stephane Lapointe <slapointe@users.noreply.github.com>
Co-authored-by: Hannah Hunter <94493363+hhunter-ms@users.noreply.github.com>
Co-authored-by: moreyhat <moreyhat@gmail.com>
Co-authored-by: Taction <zchao9100@gmail.com>
Co-authored-by: Doug Davis <duglin@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Thorsten Hans <thorsten.hans@outlook.com>
Co-authored-by: Alessandro (Ale) Segala <43508+ItalyPaleAle@users.noreply.github.com>
Co-authored-by: Pravin Pushkar <ppushkar@microsoft.com>
Co-authored-by: Fabian Steinbach <63794579+fabistb@users.noreply.github.com>
Co-authored-by: Jack Liu shurui <jackliusr@gmail.com>
  • Loading branch information
16 people committed May 18, 2022
1 parent 7f8532b commit e1f6e88
Show file tree
Hide file tree
Showing 41 changed files with 271 additions and 191 deletions.
4 changes: 2 additions & 2 deletions daprdocs/content/en/concepts/configuration-concept.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ spec:
This configuration configures tracing for metrics recording. It can be loaded in local self-hosted mode by editing the default configuration file called `config.yaml` file in your `.dapr` directory, or by applying it to your Kubernetes cluster with kubectl/helm.

Here is an example of the Dapr control plane configuration in the `daprsystem` namespace.
Here is an example of the Dapr control plane configuration called `daprsystem` in the `dapr-system` namespace.

```yaml
apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
name: daprsystem
namespace: default
namespace: dapr-system
spec:
mtls:
enabled: true
Expand Down
7 changes: 5 additions & 2 deletions daprdocs/content/en/concepts/dapr-services/sentry.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ The Dapr Sentry service manages mTLS between services and acts as a certificate

## Self-hosted mode

The sentry service Docker container is started automatically as part of [`dapr init`]({{< ref self-hosted-with-docker.md >}}). It can also be run manually as a process if you are running in [slim-init mode]({{< ref self-hosted-no-docker.md >}}).
The Sentry service Docker container is not started automatically as part of [`dapr init`]({{< ref self-hosted-with-docker.md >}}). However it can be executed manually by following the instructions for setting up [mutual TLS]({{< ref "mtls.md#self-hosted" >}}).


It can also be run manually as a process if you are running in [slim-init mode]({{< ref self-hosted-no-docker.md >}}).

<img src="/images/security-mTLS-sentry-selfhosted.png" width=1000>

Expand All @@ -23,4 +26,4 @@ The sentry service is deployed as part of `dapr init -k`, or via the Dapr Helm c

- [Security overview]({{< ref security-concept.md >}})
- [Self-hosted mode]({{< ref self-hosted-with-docker.md >}})
- [Kubernetes mode]({{< ref kubernetes >}})
- [Kubernetes mode]({{< ref kubernetes >}})
2 changes: 1 addition & 1 deletion daprdocs/content/en/concepts/security-concept.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ By default Dapr doesn't transform the state data from applications. This means D

However application state often needs to get encrypted at rest to provide stronger security in enterprise workloads or regulated environments and Dapr does provide automatic client side state encryption based on AES256. Read [How-To: Encrypt application state]({{< ref howto-encrypt-state.md >}}) for more details.

## Dapr Runtrime state
## Dapr Runtime state
Importantly the Dapr runtime does not store any data at rest, meaning that Dapr runtime has no dependency on any state stores for its operation and can be considered stateless.

# Using security capabilies in an example application
Expand Down
4 changes: 3 additions & 1 deletion daprdocs/content/en/contributing/codespaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,6 @@ git reset --hard
```

## Related links
- [GitHub documentation](https://docs.github.com/en/codespaces/overview)
<!-- IGNORE_LINKS -->
- [GitHub documentation](https://docs.github.com/github/developing-online-with-codespaces/about-codespaces)
<!-- END_IGNORE -->
2 changes: 1 addition & 1 deletion daprdocs/content/en/contributing/contributing-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Diagrams should be;
- Named using the convention of a concept or building block so that they are grouped. For example `service-invocation-overview.png`. Also see Images guidance section below.
- Added to the correct section in the `Dapr-Diagrams.pptx` deck so that they can be amended and updated.

{{< button text="Download the Dapr Diagrams Deck" link="/presentations/Dapr-Diagrams.zip" >}}
{{< button text="Download the Dapr Diagrams Deck" link="/presentations/Dapr-Diagrams.pptx.zip" >}}


## Contributing a new docs page
Expand Down
4 changes: 2 additions & 2 deletions daprdocs/content/en/contributing/presentations.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ description: How to give a presentation on Dapr and examples

We welcome community members giving presentations on Dapr and spreading the word about all the awesome Dapr features! We offer a template PowerPoint file to get started.

{{< button text="Download the Dapr Presentation Deck" link="/presentations/dapr-slidedeck.zip" >}}
{{< button text="Download the Dapr Presentation Deck" link="/presentations/dapr-slidedeck.pptx.zip" >}}

## Giving a Dapr presentation

- Begin by downloading the [Dapr Presentation Deck](/presentations/dapr-slidedeck.zip). This contains slides and diagrams needed to give a Dapr presentation.
- Begin by downloading the [Dapr Presentation Deck](/presentations/dapr-slidedeck.pptx.zip). This contains slides and diagrams needed to give a Dapr presentation.
- Next, review the docs to make sure you understand the [concepts]({{< ref concepts >}}).
- Use the Dapr [quickstarts](https://github.com/dapr/quickstarts) repo and [samples](https://github.com/dapr/samples) repo to show demos of how to use Dapr.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ spec:

Below are code examples that leverage Dapr SDKs to interact with an output binding.

{{< tabs Dotnet Java Python Go Javascript>}}
{{< tabs Dotnet Java Python Go JavaScript>}}

{{% codetab %}}

Expand All @@ -117,17 +117,18 @@ namespace EventService
{
static async Task Main(string[] args)
{
string BINDING_NAME = "checkout";
string BINDING_OPERATION = "create";
while(true) {
string BINDING_NAME = "checkout";
string BINDING_OPERATION = "create";
while(true)
{
System.Threading.Thread.Sleep(5000);
Random random = new Random();
int orderId = random.Next(1,1000);
using var client = new DaprClientBuilder().Build();
//Using Dapr SDK to invoke output binding
await client.InvokeBindingAsync(BINDING_NAME, BINDING_OPERATION, orderId);
Console.WriteLine("Sending message: " + orderId);
}
}
}
}
}
Expand Down Expand Up @@ -268,38 +269,36 @@ dapr run --app-id orderprocessing --app-port 6001 --dapr-http-port 3601 --dapr-g

```javascript
//dependencies
import { DaprServer, DaprClient, CommunicationProtocolEnum } from 'dapr-client';
import { DaprClient, CommunicationProtocolEnum } from "dapr-client";
//code
const daprHost = "127.0.0.1";
var main = function() {
for(var i=0;i<10;i++) {
sleep(5000);
var orderId = Math.floor(Math.random() * (1000 - 1) + 1);
start(orderId).catch((e) => {
const daprHost = "127.0.0.1";
(async function () {
for (var i = 0; i < 10; i++) {
await sleep(2000);
const orderId = Math.floor(Math.random() * (1000 - 1) + 1);
try {
await sendOrder(orderId)
} catch (err) {
console.error(e);
process.exit(1);
});
}
}
}
})();
async function start(orderId) {
async function sendOrder(orderId) {
const BINDING_NAME = "checkout";
const BINDING_OPERATION = "create";
const client = new DaprClient(daprHost, process.env.DAPR_HTTP_PORT, CommunicationProtocolEnum.HTTP);
//Using Dapr SDK to invoke output binding
const result = await client.binding.send(BINDING_NAME, BINDING_OPERATION, { orderId: orderId });
const result = await client.binding.send(BINDING_NAME, BINDING_OPERATION, orderId);
console.log("Sending message: " + orderId);
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
main();
```

Navigate to the directory containing the above code, then run the following command to launch a Dapr sidecar and run the application:
Expand All @@ -317,7 +316,7 @@ All that's left now is to invoke the output bindings endpoint on a running Dapr
You can also invoke the output bindings endpoint using HTTP:

```bash
curl -X POST -H 'Content-Type: application/json' http://localhost:3601/v1.0/bindings/checkout -d '{ "data": { "orderId": "100" }, "operation": "create" }'
curl -X POST -H 'Content-Type: application/json' http://localhost:3601/v1.0/bindings/checkout -d '{ "data": 100, "operation": "create" }'
```

As seen above, you invoked the `/binding` endpoint with the name of the binding to invoke, in our case its `checkout`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Now configure your application to receive incoming events. If using HTTP, you ne

Below are code examples that leverage Dapr SDKs to demonstrate an output binding.

{{< tabs Dotnet Java Python Go Javascript>}}
{{< tabs Dotnet Java Python Go JavaScript>}}

{{% codetab %}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ with DaprClient() as d:
# Create a typed message with content type and body
resp = d.publish_event(
pubsub_name='pubsub',
topic='TOPIC_A',
topic_name='TOPIC_A',
data=json.dumps(req_data),
publish_metadata={'rawPayload': 'true'}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,17 @@ With the HTTP API, you can set content type via URL query parameter `metadata.co

With the gRPC API, you can set content type by adding key/value pair `"contentType" : <content type>` to the request metadata.

### Bulk operations
### Multiple operations

Dapr supports two types of bulk operations: **bulk** or **multi**. You can group several requests of the same type into a bulk (or a batch). Dapr submits requests in bulk operations as individual requests to the underlying data store. In other words, bulk operations are not transactional. On the other hand, you can group requests of different types into a multi-operation, which is then handled as an atomic transaction.
Dapr supports two types of multi-read or multi-write operations: **bulk** or **transactional**. Read the [API reference]({{< ref state_api.md >}}) to learn how use bulk and multi options.

Read the [API reference]({{< ref state_api.md >}}) to learn how use bulk and multi options.
#### Bulk read operations

You can group multiple read requests into a bulk (or batch) operation. In the bulk operation, Dapr submits the read requests as individual requests to the underlying data store, and returns them as a single result.

#### Transactional operations

You can group write, update and delete operations into a request, which are then handled as an atomic transaction. The request will succeed or fail as a transactional set of operations.

### State encryption
Dapr supports automatic client encryption of application state with support for key rotations. This is supported on all Dapr state stores. For more info, read the [How-To: Encrypt application state]({{< ref howto-encrypt-state.md >}}) topic.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ from dapr.clients import DaprClient
DAPR_STORE_NAME = "statestore"

with DaprClient() as client:
client.save_state(DAPR_STORE_NAME, "order_1", str(orderId), metadata=(
('ttlInSeconds', '120')
))
client.save_state(DAPR_STORE_NAME, "order_1", str(orderId), state_metadata={
'ttlInSeconds': '120'
})

```

Expand Down Expand Up @@ -83,4 +83,4 @@ See [this guide]({{< ref state_api.md >}}) for a reference on the state API.

- Learn [how to use key value pairs to persist a state]({{< ref howto-get-save-state.md >}})
- List of [state store components]({{< ref supported-state-stores >}})
- Read the [API reference]({{< ref state_api.md >}})
- Read the [API reference]({{< ref state_api.md >}})
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ In the case of the hello world quickstart, two applications are launched, each w
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/app.js",
"program": "${workspaceFolder}/node/app.js",
"preLaunchTask": "daprd-debug-node",
"postDebugTask": "daprd-down-node"
},
{
"type": "python",
"request": "launch",
"name": "Pythonapp with Dapr",
"program": "${workspaceFolder}/app.py",
"program": "${workspaceFolder}/python/app.py",
"console": "integratedTerminal",
"preLaunchTask": "daprd-debug-python",
"postDebugTask": "daprd-down-python"
Expand Down Expand Up @@ -123,7 +123,7 @@ For this example the compound configuration is:
```json
{
"version": "2.0.0",
"tasks": [...],
"configurations": [...],
"compounds": [
{
"name": "Node/Python Dapr",
Expand Down
63 changes: 43 additions & 20 deletions daprdocs/content/en/getting-started/get-started-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,30 @@ weight: 30
description: "Run a Dapr sidecar and try out the state API"
---

Running [`dapr init`]({{<ref install-dapr-selfhost.md>}}) loads your local environment with:
In this guide, you'll simulate an application by running the sidecar and calling the API directly. After running Dapr using the Dapr CLI, you'll:

- The Dapr sidecar binaries.
- Default Redis component definitions for both:
- State management, and
- A message broker.
- Save a state object.
- Read/get the state object.
- Delete the state object.

With this setup, run Dapr using the Dapr CLI and try out the state API to store and retrieve a state. [Learn more about the state building block and how it works in our concept docs]({{< ref state-management >}}).
[Learn more about the state building block and how it works in our concept docs]({{< ref state-management >}}).

In this guide, you will simulate an application by running the sidecar and calling the API directly. For the purpose of this tutorial you'll run the sidecar without an application.
### Pre-requisites

- [Install Dapr CLI]({{< ref install-dapr-cli.md >}}).
- [Run `dapr init`]({{< ref install-dapr-selfhost.md>}}).

### Step 1: Run the Dapr sidecar

One of the most useful Dapr CLI commands is [`dapr run`]({{< ref dapr-run.md >}}). This command launches an application, together with a sidecar.
The [`dapr run`]({{< ref dapr-run.md >}}) command launches an application, together with a sidecar.

Launch a Dapr sidecar that will listen on port 3500 for a blank application named `myapp`:

```bash
dapr run --app-id myapp --dapr-http-port 3500
```

Since no custom component folder was defined with the above command, Dapr uses the default component definitions created during the [`dapr init` flow]({{< ref install-dapr-selfhost.md >}}), found:

- On Windows, under `%UserProfile%\.dapr\components`
- On Linux/MacOS, under `~/.dapr/components`

These tell Dapr to use the local Docker container for Redis as a state store and message broker.
Since no custom component folder was defined with the above command, Dapr uses the default component definitions created during the [`dapr init` flow]({{< ref "install-dapr-selfhost.md#step-5-verify-components-directory-has-been-initialized" >}}).

### Step 2: Save state

Expand All @@ -47,37 +44,39 @@ Update the state with an object. The new state will look like this:
]
```

Notice, the object contained in the state has a `key` assigned with the value `name`. You will use the key in the next step.
Notice, that objects contained in the state each have a `key` assigned with the value `name`. You will use the key in the next step.

Store the new state using the following command:
Save a new state object using the following command:

{{< tabs "HTTP API (Bash)" "HTTP API (PowerShell)">}}
{{% codetab %}}

```bash
curl -X POST -H "Content-Type: application/json" -d '[{ "key": "name", "value": "Bruce Wayne"}]' http://localhost:3500/v1.0/state/statestore
```

{{% /codetab %}}

{{% codetab %}}

```powershell
Invoke-RestMethod -Method Post -ContentType 'application/json' -Body '[{ "key": "name", "value": "Bruce Wayne"}]' -Uri 'http://localhost:3500/v1.0/state/statestore'
```

{{% /codetab %}}

{{< /tabs >}}

### Step 3: Get state

Retrieve the object you just stored in the state by using the state management API with the key `name`. Run the following code with the same Dapr instance you ran earlier. :
Retrieve the object you just stored in the state by using the state management API with the key `name`. In the same terminal window, run the following command:

{{< tabs "HTTP API (Bash)" "HTTP API (PowerShell)">}}

{{% codetab %}}

```bash
curl http://localhost:3500/v1.0/state/statestore/name
curl http://localhost:3500/v1.0/state/statestore/name
```

{{% /codetab %}}
Expand Down Expand Up @@ -109,7 +108,7 @@ keys *
**Output:**
`1) "myapp||name"`

View the state value by running:
View the state values by running:

```bash
hgetall "myapp||name"
Expand All @@ -121,10 +120,34 @@ hgetall "myapp||name"
`3) "version"`
`4) "1"`

Exit the redis-cli with:
Exit the Redis CLI with:

```bash
exit
```

### Step 5: Delete state

In the same terminal window, delete the`name` state object from the state store.

{{< tabs "HTTP API (Bash)" "HTTP API (PowerShell)">}}

{{% codetab %}}

```bash
curl -v -X DELETE -H "Content-Type: application/json" http://localhost:3500/v1.0/state/statestore/name
```

{{% /codetab %}}

{{% codetab %}}

```powershell
Invoke-RestMethod -Method Delete -ContentType 'application/json' -Uri 'http://localhost:3500/v1.0/state/statestore/name'
```

{{% /codetab %}}

{{< /tabs >}}

{{< button text="Next step: Dapr Quickstarts >>" page="getting-started/quickstarts" >}}
Loading

0 comments on commit e1f6e88

Please sign in to comment.