### Dapr workflow start response example Source: https://docs.dapr.io/reference/api/_print Example of a successful response when starting a Dapr workflow, containing the unique instance ID assigned to the new workflow. ```json { "instanceID": "12345678" } ``` -------------------------------- ### Get Configuration Item - cURL Example Source: https://docs.dapr.io/reference/api/_print Example of how to retrieve a specific configuration item using cURL. This command interacts with the Dapr API to fetch the value associated with 'myConfigKey'. ```bash curl -X GET 'http://localhost:3500/v1.0/configuration/mystore?key=myConfigKey' ``` -------------------------------- ### Example: Set State with Options Source: https://docs.dapr.io/reference/api/state_api An example of a `POST` request to the state API including options for concurrency and consistency. ```APIDOC ## Example: Set State with Options ### Method POST ### Endpoint `/v1.0/state/{statestorename}` ### Request Body ```json [ { "key": "weapon", "value": "DeathStar", "etag": "xxxxx", "options": { "concurrency": "first-write", "consistency": "strong" } } ] ``` ### Request Example (curl) ```bash curl -X POST http://localhost:3500/v1.0/state/starwars \ -H "Content-Type: application/json" \ -d '[ { "key": "weapon", "value": "DeathStar", "etag": "xxxxx", "options": { "concurrency": "first-write", "consistency": "strong" } } ]' ``` ``` -------------------------------- ### Subscribe to Configuration Changes - cURL Example Source: https://docs.dapr.io/reference/api/_print Example of subscribing to configuration changes using cURL. This command targets the Dapr API to set up a subscription for 'myConfigKey'. ```bash curl -X GET 'http://localhost:3500/v1.0/configuration/mystore/subscribe?key=myConfigKey' ``` -------------------------------- ### Dapr Configuration Subscription Example JSON Source: https://docs.dapr.io/reference/api/configuration_api An example of a Dapr configuration subscription request body. This illustrates the expected format with sample data for subscription ID, item key, value, and version. ```json { "id": "bf3aa454-312d-403c-af95-6dec65058fa2", "items": [ "key": "config-1", "value": "abcdefgh", "version": "1.1" ] } ``` -------------------------------- ### Dapr State API: Bulk Get State Example (curl) Source: https://docs.dapr.io/reference/api/state_api Demonstrates how to retrieve multiple state items in bulk using the Dapr State API with a curl command. This includes specifying keys and parallelism, and shows the expected JSON response format for retrieved key-value pairs. ```shell curl http://localhost:3500/v1.0/state/myRedisStore/bulk \ -H "Content-Type: application/json" \ -d '{ "keys": [ "key1", "key2" ], "parallelism": 10 }' ``` ```json [ { "key": "key1", "value": "value1", "etag": "1" }, { "key": "key2", "value": "value2", "etag": "1" } ] ``` -------------------------------- ### Start Workflow Source: https://docs.dapr.io/reference/api/workflow_api Starts a workflow instance with a given name and optional instance ID. Workflow instance IDs can only contain alphanumeric characters, underscores, and dashes. ```APIDOC ## POST /v1.0/workflows///start ### Description Starts a workflow instance with the given name and optionally, an instance ID. ### Method POST ### Endpoint `http://localhost:/v1.0/workflows///start[?instanceID=]` ### Parameters #### Path Parameters - **workflowComponentName** (string) - Required - Use `dapr` for Dapr Workflows. - **workflowName** (string) - Required - Identifies the workflow type. #### Query Parameters - **instanceID** (string) - Optional - Unique value created for each run of a specific workflow. Can only contain alphanumeric characters, underscores, and dashes. #### Request Body Any request content will be passed to the workflow as input. The Dapr API passes the content as-is without attempting to interpret it. ### Response #### Success Response (202) Accepted #### Response Example ```json { "instanceID": "12345678" } ``` #### Error Responses - **400** - Request was malformed - **500** - Request formatted correctly, error in dapr code ``` -------------------------------- ### State Management with ETags Source: https://docs.dapr.io/reference/api/_print Examples demonstrating how to set, get, update, and delete objects in a state store using ETags for concurrency control. ```APIDOC ## POST /v1.0/state/{statestore} ### Description Stores an object in a state store. ### Method POST ### Endpoint /v1.0/state/{statestore} ### Parameters #### Path Parameters - **statestore** (string) - Required - The name of the state store component. #### Request Body - **key** (string) - Required - The key of the state to store. - **value** (any) - Required - The value of the state to store. - **etag** (string) - Optional - The ETag to use for optimistic concurrency control when updating. ### Request Example ```json [ { "key": "sampleData", "value": "1" } ] ``` ### Response #### Success Response (200) Indicates the state was successfully saved. ## GET /v1.0/state/{statestore}/{key} ### Description Retrieves an object from a state store and includes its ETag. ### Method GET ### Endpoint /v1.0/state/{statestore}/{key} ### Parameters #### Path Parameters - **statestore** (string) - Required - The name of the state store component. - **key** (string) - Required - The key of the state to retrieve. ### Response #### Success Response (200) - **value** (any) - The retrieved state value. - **etag** (string) - The ETag of the retrieved state. ### Response Example ```json "1" ``` ## POST /v1.0/state/{statestore} (Update with ETag) ### Description Updates an object in a state store using a specified ETag for concurrency control. ### Method POST ### Endpoint /v1.0/state/{statestore} ### Parameters #### Path Parameters - **statestore** (string) - Required - The name of the state store component. #### Request Body - **key** (string) - Required - The key of the state to update. - **value** (any) - Required - The new value of the state. - **etag** (string) - Required - The ETag of the current state to match for the update. ### Request Example ```json [ { "key": "sampleData", "value": "2", "etag": "1" } ] ``` ### Response #### Success Response (200) Indicates the state was successfully updated. ## DELETE /v1.0/state/{statestore}/{key} ### Description Deletes an object from a state store. ### Method DELETE ### Endpoint /v1.0/state/{statestore}/{key} ### Parameters #### Path Parameters - **statestore** (string) - Required - The name of the state store component. - **key** (string) - Required - The key of the state to delete. #### Headers - **If-Match** (string) - Required - The ETag of the current state to match for the delete operation. ### Response #### Success Response (200) Indicates the state was successfully deleted. ``` -------------------------------- ### Get Placement Table State (Curl) Source: https://docs.dapr.io/reference/api/_print Example using curl to fetch the Dapr placement table state. This demonstrates how to query the API endpoint and the expected JSON response structure. ```shell curl localhost:8080/placement/state ``` -------------------------------- ### Reminder Request Body Examples (JSON) Source: https://docs.dapr.io/reference/api/actors_api Provides examples of JSON request bodies for creating actor reminders, demonstrating different configurations for `dueTime`, `period`, and `ttl`. These examples illustrate single-fire reminders, immediate and periodic reminders, and reminders with repetition counts. ```json { "dueTime":"0h0m3s0ms", "period":"0h0m7s0ms" } ``` ```json { "dueTime":"0h0m0s0ms", "period":"0h0m9s0ms" } ``` ```json { "dueTime":"0h0m3s0ms", "period":"" } ``` ```json { "period":"PT3S", "ttl":"20s" } ``` ```json { "data": "someData", "dueTime": "1m", "period": "20s" } ``` -------------------------------- ### Invoking App with Input Bindings (Python Example) Source: https://docs.dapr.io/reference/api/bindings_api Demonstrates how an application can receive events from an input binding by exposing an HTTP POST endpoint that matches the binding component's name. Includes a Python Flask example. ```APIDOC ## Invoking Service Code Through Input Bindings Applications can subscribe to events from input bindings by exposing an HTTP POST endpoint. The route name for this endpoint must match the `metadata.name` defined in the corresponding binding component YAML. ### Example: Kafka Input Binding First, define the Kafka binding component: ```yaml apiVersion: dapr.io/v1alpha1 kind: Component metadata: name: kafkaevent spec: type: bindings.kafka version: v1 metadata: - name: brokers value: "http://localhost:5050" - name: topics value: "someTopic" - name: publishTopic value: "someTopic2" - name: consumerGroup value: "group1" ``` Then, create a Python application that listens for POST requests on the `/kafkaevent` route: ```python from flask import Flask app = Flask(__name__) @app.route("/kafkaevent", methods=['POST']) def incoming(): print("Hello from Kafka!", flush=True) return "Kafka Event Processed!" ``` When Dapr receives an event for the `kafkaevent` binding, it will send a POST request to `http://localhost:/kafkaevent`. ``` -------------------------------- ### Get State with Metadata using Dapr State Management API Source: https://docs.dapr.io/reference/api/state_api Provides an example of retrieving state while passing additional metadata as query parameters in the URL. This is useful for specifying partition keys or content types. ```curl GET http://localhost:3500/v1.0/state/starwars/planet?metadata.partitionKey=mypartitionKey&metadata.contentType=application/json ``` -------------------------------- ### Example: Invoking Kafka Output Binding with cURL Source: https://docs.dapr.io/reference/api/_print An example using cURL to invoke a Dapr output binding named 'myKafka'. It demonstrates how to send a JSON payload with data, metadata, and the 'create' operation. ```bash curl -X POST http://localhost:3500/v1.0/bindings/myKafka \ -H "Content-Type: application/json" \ -d '{ "data": { "message": "Hi" }, "metadata": { "key": "redis-key-1" }, "operation": "create" }' ``` -------------------------------- ### Dapr State Binding Example Source: https://docs.dapr.io/reference/api/bindings_api An example of a Dapr response body used to bind input bindings with state stores or output bindings. It demonstrates storing data and sending messages to multiple output bindings concurrently. ```json { "storeName": "stateStore", "state": stateDataToStore, "to": ['storage', 'queue'], "concurrency": "parallel", "data": jsonObject, } ``` -------------------------------- ### Dapr State API: Query State Example (URL) Source: https://docs.dapr.io/reference/api/state_api Illustrates how to construct a URL for querying state using the Dapr State API's alpha endpoint. This example shows the basic POST/PUT request structure to a /query endpoint, including placeholders for Dapr port and store name. ```http POST/PUT http://localhost:/v1.0-alpha1/state//query ``` -------------------------------- ### Dapr Subscribe Endpoint for Topic Discovery Source: https://docs.dapr.io/reference/api/pubsub_api This is an example of an HTTP GET request that Dapr invokes on user code to discover topic subscriptions. The application should respond with a list of its subscriptions. ```http GET http://localhost:/dapr/subscribe ``` -------------------------------- ### Query State Response Example Source: https://docs.dapr.io/reference/api/_print Example JSON response from a state query operation, showing an array of results with key, data, and etag, along with a pagination token. ```json { "results": [ { "key": "1", "data": { "person": { "org": "Dev Ops", "id": 1036 }, "city": "Seattle", "state": "WA" }, "etag": "6f54ad94-dfb9-46f0-a371-e42d550adb7d" }, { "key": "4", "data": { "person": { "org": "Dev Ops", "id": 1042 }, "city": "Spokane", "state": "WA" }, "etag": "7415707b-82ce-44d0-bf15-6dc6305af3b1" }, { "key": "10", "data": { "person": { "org": "Dev Ops", "id": 1054 }, "city": "New York", "state": "NY" }, "etag": "26bbba88-9461-48d1-8a35-db07c374e5aa" } ], "token": "3" } ``` -------------------------------- ### Invoke Dapr Actor Method Example (curl) Source: https://docs.dapr.io/reference/api/_print Example using curl to invoke a method on a Dapr actor. The first example shows a simple invocation, while the second demonstrates passing parameters in the request body. It requires the Dapr port, actor type, actor ID, and method name. ```shell curl -X POST http://localhost:3500/v1.0/actors/stormtrooper/50/method/shoot \ -H "Content-Type: application/json" ``` ```shell curl -X POST http://localhost:3500/v1.0/actors/x-wing/33/method/fly \ -H "Content-Type: application/json" \ -d '{ "destination": "Hoth" }' ``` ```shell curl -X POST http://localhost:3500/v1.0/actors/x-wing/33/method/fly \ -H "Content-Type: application/json" \ -d "{\"destination\":\"Hoth\"}" ``` -------------------------------- ### Dapr Kafka Binding Component Example Source: https://docs.dapr.io/reference/api/bindings_api An example of a Dapr component configuration for a Kafka binding. This YAML specifies connection details like brokers, topics for publishing and subscribing, and the consumer group, along with the binding direction. ```yaml apiVersion: dapr.io/v1alpha1 kind: Component metadata: name: kafkaevent spec: type: bindings.kafka version: v1 metadata: - name: brokers value: "http://localhost:5050" - name: topics value: "someTopic" - name: publishTopic value: "someTopic2" - name: consumerGroup value: "group1" - name: "direction" value: "input, output" ``` -------------------------------- ### Dapr State API: Passing Metadata in URL (Example) Source: https://docs.dapr.io/reference/api/state_api Demonstrates how to pass optional metadata as query parameters in Dapr State API requests. This example shows appending `?metadata.partitionKey=mypartitionKey` to a bulk state operation URL. ```http POST/PUT http://localhost:3500/v1.0/state/myStore/bulk?metadata.partitionKey=mypartitionKey ``` ```http POST http://localhost:3500/v1.0-alpha1/state/myStore/query?metadata.contentType=application/json ``` ```http DELETE http://localhost:3500/v1.0/state/myStore/myKey?metadata.contentType=application/json ``` -------------------------------- ### Get Configuration from Dapr Store Source: https://docs.dapr.io/reference/api/_print Illustrates the HTTP GET request to retrieve configuration values from a specified Dapr configuration store. Requires the Dapr port and the name of the configuration store. ```http GET http://localhost:/v1.0/configuration/ ``` -------------------------------- ### Dapr State Set Request Example (curl) Source: https://docs.dapr.io/reference/api/state_api An example `curl` command to perform a POST request to set state in Dapr. It includes a JSON payload with key, value, etag, and options for concurrency and consistency. ```curl curl -X POST http://localhost:3500/v1.0/state/starwars \ -H "Content-Type: application/json" \ -d [ { "key": "weapon", "value": "DeathStar", "etag": "xxxxx", "options": { "concurrency": "first-write", "consistency": "strong" } } ] ``` -------------------------------- ### State Transaction - cURL Example Source: https://docs.dapr.io/reference/api/_print Example of performing a state transaction using cURL. This involves sending a POST request with operations (upsert, delete) and optional metadata to a specified store. ```bash POST http://localhost:3500/v1.0/state/myStore/transaction?metadata.contentType=application/json ``` -------------------------------- ### Node.js Example for Receiving Dapr Invocation Source: https://docs.dapr.io/reference/api/service_invocation_api A Node.js Express.js example illustrating how a service can listen for and process incoming invocation requests from Dapr. It shows how to parse the request body and send a response. ```javascript app.post('/add', (req, res) => { let args = req.body; const [operandOne, operandTwo] = [Number(args['arg1']), Number(args['arg2'])]; let result = operandOne + operandTwo; res.send(result.toString()); }); app.listen(port, () => console.log(`Listening on port ${port}!`)); ``` -------------------------------- ### Service Invocation Request Headers Example Source: https://docs.dapr.io/reference/api/_print Provides an example of HTTP headers that can be included when making a service invocation request through Dapr. This allows for passing necessary metadata, such as content type, to the invoked service. ```json { "Content-Type": "application/json" } ``` -------------------------------- ### Dapr Job Request Body Example Source: https://docs.dapr.io/reference/api/jobs_api Example of a request body for scheduling a Dapr job, including 'data' and 'dueTime' parameters. 'dueTime' can be specified in various formats like RFC3339 or Go duration strings. ```json { "data": "some data", "dueTime": "30s" } ``` -------------------------------- ### Invoke Actor Method Example (curl) Source: https://docs.dapr.io/reference/api/actors_api Example using curl to send a POST request to invoke a method on a specific actor instance. Specifies the actor type, ID, and method name in the URL. ```shell curl -X POST http://localhost:3000/actors/stormtrooper/50/method/performAction \ -H "Content-Type: application/json" ``` -------------------------------- ### Health Check Example Source: https://docs.dapr.io/reference/api/_print Example of how to get a health check response from an application using cURL. ```APIDOC ## Health Check Example ### Description This example demonstrates how to perform a health check on an application by sending a GET request to the `/healthz` endpoint. ### Method GET ### Endpoint `http://localhost:3000/healthz` ### Request Example ```bash curl -X GET http://localhost:3000/healthz ``` ### Response Example (A successful response would typically be an empty body or a simple JSON indicating health, e.g., `{"status": "healthy"}`) ``` -------------------------------- ### Dapr Secrets API: Get Secret (Multi-Key Response Example) Source: https://docs.dapr.io/reference/api/_print Demonstrates an example HTTP request and response for retrieving secrets using the Dapr Secrets API. This specific example showcases a response from a secret store that supports multiple key-value pairs within a single secret, such as Kubernetes Secrets. The response body contains the secret data as a JSON object with keys and values. ```curl curl http://localhost:3500/v1.0/secrets/kubernetes/db-secret ``` ```json { "key1": "value1", "key2": "value2" } ``` -------------------------------- ### Example: Working with ETags Source: https://docs.dapr.io/reference/api/state_api Demonstrates the workflow of storing, retrieving, and updating data using ETags with a state store. ```APIDOC ## Example: Working with ETags ### 1. Store an object: #### Method POST #### Endpoint `/v1.0/state/{statestorename}` #### Request Body ```json [ { "key": "sampleData", "value": "1" } ] ``` #### Request Example (curl): ```bash curl -X POST http://localhost:3500/v1.0/state/statestore \ -H "Content-Type: application/json" \ -d '[ { "key": "sampleData", "value": "1" } ]' ``` ### 2. Get the object to retrieve the ETag: #### Method GET #### Endpoint `/v1.0/state/{statestorename}/{key}` #### Response Example (curl): ```bash curl http://localhost:3500/v1.0/state/statestore/sampleData -v * Connected to localhost (127.0.0.1) port 3500 (#0) > GET /v1.0/state/statestore/sampleData HTTP/1.1 > Host: localhost:3500 > User-Agent: curl/7.64.1 > Accept: */* > < HTTP/1.1 200 OK < Server: fasthttp < Date: Sun, 14 Feb 2021 04:51:50 GMT < Content-Type: application/json < Content-Length: 3 < Etag: 1 < Traceparent: 00-3452582897d134dc9793a244025256b1-b58d8d773e4d661d-01 * < "1" * Connection #0 to host localhost left intact ``` *The returned ETag is `1`.* ### 3. Update the object (with or without ETag): * **Omitting ETag (last-write-wins):** ```bash curl -X POST http://localhost:3500/v1.0/state/statestore \ -H "Content-Type: application/json" \ -d '[ { "key": "sampleData", "value": "2" } ]' ``` * **With correct ETag:** The update will succeed. * **With incorrect ETag:** An error will be returned (e.g., `ERR_STATE_SAVE`). ```bash curl -X POST http://localhost:3500/v1.0/state/statestore \ -H "Content-Type: application/json" \ -d '[ { "key": "sampleData", "value": "2", "etag": "2" } ]' ``` ``` -------------------------------- ### Get Health Check Response (curl) Source: https://docs.dapr.io/reference/api/_print Example of how to retrieve a health check response from a Dapr application using curl. This is useful for monitoring application status. ```shell curl -X GET http://localhost:3000/healthz \ ``` -------------------------------- ### Perform State Set with Strong Consistency (Dapr API) Source: https://docs.dapr.io/reference/api/_print This example shows how to perform a state 'set' operation with specific options, including first-write concurrency control and strong consistency. It utilizes the Dapr state API and requires a Dapr sidecar and a compatible state store. ```shell curl -X POST http://localhost:3500/v1.0/state/starwars \ -H "Content-Type: application/json" \ -d '[ \ { "key": "weapon", "value": "DeathStar", "etag": "xxxxx", "options": { "concurrency": "first-write", "consistency": "strong" } } \ ]' ``` -------------------------------- ### Dapr Secrets API: Get Secret with Query Parameters (Version ID Example) Source: https://docs.dapr.io/reference/api/_print Illustrates how to use query parameters with the Dapr Secrets API to provide additional metadata for secret retrieval. This example shows a request including the `metadata.version_id` parameter, which is supported by certain secret stores like Hashicorp Vault, GCP Secret Manager, and AWS Secret Manager for specifying a particular secret version. ```http GET http://localhost:/v1.0/secrets//?metadata.version_id=15 ``` -------------------------------- ### Get State using Dapr (curl) Source: https://docs.dapr.io/reference/api/_print This curl command illustrates how to retrieve the state associated with a specific key from a Dapr state store. It includes an example of passing metadata like content type via URL parameters. ```shell curl http://localhost:3500/v1.0/state/starwars/planet?metadata.contentType=application/json ``` -------------------------------- ### Start a Dapr workflow instance Source: https://docs.dapr.io/reference/api/_print Initiates a workflow instance with a specified component name and workflow name. An optional instance ID can be provided for unique identification. The request body is passed as input to the workflow. ```http POST http://localhost:/v1.0/workflows///start[?instanceID=] ``` -------------------------------- ### Dapr Binding Discovery HTTP Request Source: https://docs.dapr.io/reference/api/bindings_api Illustrates the HTTP OPTIONS request Dapr sends to an application's endpoint during startup to discover binding capabilities. The application's response code determines if it wants to bind to the specified Dapr binding. ```http OPTIONS http://localhost:/ ``` -------------------------------- ### GET /v1.0/actors/{actorType}/{actorId}/reminders/{name} Source: https://docs.dapr.io/reference/api/_print Gets a reminder for an actor. ```APIDOC ## GET /v1.0/actors/{actorType}/{actorId}/reminders/{name} ### Description Gets a reminder for an actor. ### Method GET ### Endpoint http://localhost:/v1.0/actors///reminders/ ### Parameters #### Path Parameters - **daprPort** (integer) - Required - The Dapr port. - **actorType** (string) - Required - The actor type. - **actorId** (string) - Required - The actor ID. - **name** (string) - Required - The name of the reminder to get. ### Response #### Success Response (200) Request successful. #### Error Responses - **500**: Request failed. ``` -------------------------------- ### GET /v1.0/actors/{actorType}/{actorId}/state/{key} Source: https://docs.dapr.io/reference/api/_print Gets the state for an actor using a specified key. ```APIDOC ## GET /v1.0/actors/{actorType}/{actorId}/state/{key} ### Description Gets the state for an actor using a specified key. ### Method GET ### Endpoint http://localhost:/v1.0/actors///state/ ### Parameters #### Path Parameters - **daprPort** (integer) - Required - The Dapr port. - **actorType** (string) - Required - The actor type. - **actorId** (string) - Required - The actor ID. - **key** (string) - Required - The key for the state value. ### Request Example ``` curl http://localhost:3500/v1.0/actors/stormtrooper/50/state/location \ -H "Content-Type: application/json" ``` ### Response #### Success Response (200) - **location** (string) - The state value for the given key. #### Response Example ```json { "location": "Alderaan" } ``` #### Error Responses - **204**: Key not found, and the response will be empty. - **400**: Actor not found. - **500**: Request failed. ``` -------------------------------- ### GET /v1.0/configuration/{storename} Source: https://docs.dapr.io/reference/api/configuration_api Retrieves configuration items from a specified store. If no keys are provided, all configuration items are returned. Supports filtering by key. ```APIDOC ## GET /v1.0/configuration/{storename} ### Description Retrieves configuration items from a specified store. If no keys are provided, all configuration items are returned. Supports filtering by key. ### Method GET ### Endpoint `http://localhost:/v1.0/configuration/` ### Parameters #### Path Parameters - **daprPort** (integer) - Required - The Dapr port. - **storename** (string) - Required - The `metadata.name` of the configuration store component. #### Query Parameters - **key** (string) - Optional - The key of the configuration item to retrieve. Can be specified multiple times to retrieve multiple keys. ### Request Body None ### Response #### Success Response (204) - **JSON object** - Key/value pairs for each configuration item. #### Response Example ```json { "myConfigKey": { "value":"myConfigValue" } } ``` ``` -------------------------------- ### State Management API Reference Source: https://docs.dapr.io/reference/api/state_api Documentation for the Dapr State Management API, covering component configuration, key schemes, and API endpoints. ```APIDOC ## Component File Structure A Dapr `statestore.yaml` component file has the following structure: ```yaml apiVersion: dapr.io/v1alpha1 kind: Component metadata: name: namespace: spec: type: state. version: v1 metadata: - name: value: - name: value: ``` **Setting** | **Description** ---|--- `metadata.name` | The name of the state store. `spec/metadata` | An open key value pair metadata that allows a binding to define connection properties. ## Key Scheme Dapr state stores are key/value stores. To ensure data compatibility, Dapr requires these data stores follow a fixed key scheme. For general states, the key format is: ``` || ``` For Actor states, the key format is: ``` |||||| ``` > Since `||` is a reserved string it cannot be used in the `` field. ## Save State This endpoint lets you save an array of state objects. ### HTTP Request ``` POST http://localhost:/v1.0/state/ ``` #### URL Parameters **Parameter** | **Description** ---|--- `daprPort` | The Dapr port. `storename` | The `metadata.name` field in the user-configured `statestore.yaml` component file. Refer to the Dapr state store configuration structure mentioned above. The optional request metadata is passed via URL query parameters. For example: ``` POST http://localhost:3500/v1.0/state/myStore?metadata.contentType=application/json ``` > All URL parameters are case-sensitive. #### Request Body A JSON array of state objects. Each state object is comprised with the following fields: **Field** | **Description** ---|--- `key` | State key. `value` | State value, which can be any byte array. `etag` | (optional) State ETag. `metadata` | (optional) Additional key-value pairs to be passed to the state store. `options` | (optional) State operation options; see state operation options. > **ETag format:** Dapr runtime treats ETags as opaque strings. The exact ETag format is defined by the corresponding data store. #### Metadata Metadata can be sent via query parameters in the request’s URL. It must be prefixed with `metadata.`, as shown below. **Parameter** | **Description** ---|--- `metadata.ttlInSeconds` | The number of seconds for the message to expire, as described here. > **TTL:** Only certain state stores support the TTL option, according the supported state stores. ### HTTP Response #### Response Codes **Code** | **Description** ---|--- `204` | State saved. `400` | State store is missing or misconfigured or malformed request. `500` | Failed to save state. #### Response Body None. ### Example ```bash curl -X POST http://localhost:3500/v1.0/state/starwars?metadata.contentType=application/json \ -H "Content-Type: application/json" \ -d '[ { "key": "weapon", "value": "DeathStar", "etag": "1234" }, { "key": "planet", "value": { "name": "Tatooine" } } ]' ``` ## Get State This endpoint lets you get the state for a specific key. ### HTTP Request ``` GET http://localhost:/v1.0/state// ``` #### URL Parameters **Parameter** | **Description** ---|--- `daprPort` | The Dapr port. `storename` | `metadata.name` field in the user-configured statestore.yaml component file. Refer to the Dapr state store configuration structure mentioned above. `key` | The key of the desired state. `consistency` | (optional) Read consistency mode; see state operation options. `metadata` | (optional) Metadata as query parameters to the state store. The optional request metadata is passed via URL query parameters. For example: ``` GET http://localhost:3500/v1.0/state/myStore/myKey?metadata.contentType=application/json ``` > Note, all URL parameters are case-sensitive. ### HTTP Response #### Response Codes **Code** | **Description** ---|--- `200` | Get state successful. `204` | Key is not found. `400` | State store is missing or misconfigured. `500` | Get state failed. #### Response Headers **Header** | **Description** ---|--- `ETag` | ETag of returned value. #### Response Body JSON-encoded value. ### Example ```bash curl http://localhost:3500/v1.0/state/starwars/planet?metadata.contentType=application/json ``` > The above command returns the state: ```json { "name": "Tatooine" } ``` To pass metadata as query parameter: ``` GET http://localhost:3500/v1.0/state/starwars/planet?metadata.partitionKey=mypartitionKey&metadata.contentType=application/json ``` ## Get Bulk State This endpoint lets you get a list of values for a given list of keys. ### HTTP Request ``` POST/PUT http://localhost:/v1.0/state//bulk ``` ``` -------------------------------- ### Get Dapr Sidecar Metadata Source: https://docs.dapr.io/reference/api/metadata_api Retrieves metadata information from the Dapr sidecar. This endpoint is typically used to get details about the Dapr runtime, components, and application configuration. ```shell curl http://localhost:3500/v1.0/metadata ``` -------------------------------- ### Dapr State Key Schemes (General and Actor) Source: https://docs.dapr.io/reference/api/_print These examples illustrate the required key schemes for Dapr state stores. The general state key format is '||'. For Actor states, a more detailed format is used: '||||||', ensuring proper data organization and retrieval for both types of state management. ```plaintext || ``` ```plaintext |||||| ``` -------------------------------- ### Unsubscribe from Configuration Changes - cURL Example Source: https://docs.dapr.io/reference/api/_print Example of unsubscribing from configuration changes using cURL. This command interacts with the Dapr API to cancel an existing subscription using its ID. ```bash curl -X GET 'http://localhost:3500/v1.0-alpha1/configuration/mystore/bf3aa454-312d-403c-af95-6dec65058fa2/unsubscribe' ``` -------------------------------- ### Deactivate Actor Example (curl) Source: https://docs.dapr.io/reference/api/actors_api Example using curl to send a DELETE request to deactivate a specific actor instance. Specifies the actor type and ID in the URL. ```shell curl -X DELETE http://localhost:3000/actors/stormtrooper/50 \ -H "Content-Type: application/json" ``` -------------------------------- ### Workflow API Reference Source: https://docs.dapr.io/reference/api/_print APIs for starting and terminating workflow instances managed by Dapr. ```APIDOC ## POST /v1.0/workflows/{workflowComponentName}/{workflowName}/start ### Description Starts a workflow instance with the given name and optionally, an instance ID. ### Method POST ### Endpoint /v1.0/workflows/{workflowComponentName}/{workflowName}/start ### Parameters #### Path Parameters - **workflowComponentName** (string) - Required - Use `dapr` for Dapr Workflows. - **workflowName** (string) - Required - Identifies the workflow type. - **instanceID** (string) - Optional - Unique value created for each run of a specific workflow. Can only contain alphanumeric characters, underscores, and dashes. ### Request Content Any request content will be passed to the workflow as input. ### Response #### Success Response (202) Accepted. #### Error Response (400) Request was malformed. #### Error Response (500) Request formatted correctly, error in dapr code. ### Response Content Example ```json { "instanceID": "12345678" } ``` ## POST /v1.0/workflows/{workflowComponentName}/{instanceId}/terminate ### Description Terminates a running workflow instance with the given name and instance ID. Terminating a workflow terminates all of its child workflows and has no effect on in-flight activity executions. ### Method POST ### Endpoint /v1.0/workflows/{workflowComponentName}/{instanceId}/terminate ### Parameters #### Path Parameters - **workflowComponentName** (string) - Required - Use `dapr` for Dapr Workflows. - **instanceId** (string) - Required - Unique value created for each run of a specific workflow. ### Response #### Success Response (202) Accepted. #### Error Response (400) Request was malformed. #### Error Response (500) Request formatted correctly, error in dapr code. ### Response Content This API does not return any content. ``` -------------------------------- ### GET /v1.0/configuration/{storename} Source: https://docs.dapr.io/reference/api/_print Retrieves configuration items from a specified store. If no keys are provided, all items are returned. Otherwise, only the items matching the provided keys are returned. ```APIDOC ## GET /v1.0/configuration/{storename} ### Description Retrieves configuration items from a specified store. If no keys are provided, all items are returned. Otherwise, only the items matching the provided keys are returned. ### Method GET ### Endpoint /v1.0/configuration/{storename} #### Query Parameters - **key** (string) - Optional - The key of the configuration item to retrieve. Can be specified multiple times. ### Request Example ``` GET http://localhost:/v1.0/configuration/mystore?key=config1&key=config2 ``` ### Response #### Success Response (204) - **object** (object) - JSON-encoded value of key/value pairs for each configuration item. #### Response Example ```json { "myConfigKey": { "value":"myConfigValue" } } ``` ``` -------------------------------- ### GET /v1.0/healthz Source: https://docs.dapr.io/reference/api/health_api Gets the health state for Dapr by checking for sidecar health. This endpoint is used with Kubernetes liveness probes and waits for all components to be initialized, the Dapr HTTP port to be available, and the app channel to be initialized. ```APIDOC ## GET /v1.0/healthz ### Description Gets the health state for Dapr by checking for sidecar health. This endpoint is used with Kubernetes liveness probes and waits for all components to be initialized, the Dapr HTTP port to be available, and the app channel to be initialized. ### Method GET ### Endpoint http://localhost:/v1.0/healthz ### Parameters #### Query Parameters - **daprPort** (integer) - Required - The Dapr port ### Request Example ```bash curl -i http://localhost:3500/v1.0/healthz ``` ### Response #### Success Response (204) - **None** - Dapr is healthy #### Error Response (500) - **None** - Dapr is not healthy ``` -------------------------------- ### Conversation with Tool Calling Request (curl) Source: https://docs.dapr.io/reference/api/conversation_api This example shows how to perform a conversation request with tool calling enabled. It includes defining tools, parameters like model and max tokens, and metadata. The request asks about weather and specifies a tool for retrieval. ```shell curl -X POST http://localhost:3500/v1.0-alpha2/conversation/openai/converse \ -H "Content-Type: application/json" \ -d '{ "inputs": [ { "messages": [ { "ofUser": { "content": [ { "text": "What is the weather like in San Francisco in celsius?" } ] } } ], "scrubPii": false } ], "parameters": { "max_tokens": { "@type": "type.googleapis.com/google.protobuf.Int64Value", "value": "100" }, "model": { "@type": "type.googleapis.com/google.protobuf.StringValue", "value": "claude-3-5-sonnet-20240620" } }, "metadata": { "api_key": "test-key", "version": "1.0" }, "scrubPii": false, "temperature": 0.7, "tools": [ { "function": { "name": "get_weather", "description": "Get the current weather for a location", "parameters": { "type": "object", "properties": { "location": { "type": "string", "description": "The city and state, e.g. San Francisco, CA" }, "unit": { "type": "string", "enum": ["celsius", "fahrenheit"], "description": "The temperature unit to use" } }, "required": ["location"] } } } ], "toolChoice": "auto" }' ``` -------------------------------- ### Dapr Service Invocation Request Body Example Source: https://docs.dapr.io/reference/api/service_invocation_api Example of the JSON payload that can be sent in the body when invoking a service. This demonstrates passing arguments and operator details for a potential calculation. ```json { "arg1": 10, "arg2": 23, "operator": "+" } ``` -------------------------------- ### Invoking a Dapr Kafka Output Binding (cURL) Source: https://docs.dapr.io/reference/api/bindings_api A cURL command example demonstrating how to invoke a Dapr output binding, specifically a Kafka binding. It shows the HTTP method, URL, headers, and the JSON payload. ```bash curl -X POST http://localhost:3500/v1.0/bindings/myKafka \ -H "Content-Type: application/json" \ -d '{ "data": { "message": "Hi" }, "metadata": { "key": "redis-key-1" }, "operation": "create" }' ``` -------------------------------- ### Get Configuration Items - Dapr API Source: https://docs.dapr.io/reference/api/_print Retrieves configuration items from a Dapr configuration store. Supports fetching all items or specific keys using query parameters. Returns a JSON object of key-value pairs. Dependencies include the Dapr sidecar running and a configured configuration store. ```http GET http://localhost:/v1.0/configuration/mystore?key=config1&key=config2 GET http://localhost:/v1.0/configuration/mystore ```