Use the Dapr API

    You will now run the sidecar and call the API directly (simulating what an application would do).

    One the most useful Dapr CLI commands is dapr run. This command launches an application together with a sidecar. For the purpose of this tutorial you’ll run the sidecar without an application.

    Run the following command to launch a Dapr sidecar that will listen on port 3500 for a blank application named myapp:

    With this command, no custom component folder was defined, so Dapr uses the default component definitions that were created during the init flow (these can be found under $HOME/.dapr/components on Linux or MacOS and under %USERPROFILE%\.dapr\components on Windows). These tell Dapr to use the local Redis Docker container as a state store and message broker.

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

    Now get the state you just stored using a key with the state management API:

    With the same Dapr instance running from above run:

    With the same Dapr instance running from above run:

    1. Invoke-RestMethod -Uri 'http://localhost:3500/v1.0/state/statestore/name'

    You can look in the Redis container and verify Dapr is using it as a state store. Run the following to use the Redis CLI:

    1. docker exec -it dapr_redis redis-cli
    1. 1) "myapp||name"

    View the state value by running:

    1. hgetall "myapp||name"

    Exit the redis-cli with: