Skip to main content

Quickstart: State Management

This quickstart showcases how to enable stateful data persistence using the State API.

invoke qs

1

Prerequisites

Before you proceed, ensure you have the following prereqs installed.

2

Log in to Catalyst

Authenticate to Diagrid Catalyst using the following command:

diagrid login

Confirm your organization and user details are correct:

diagrid whoami
3

Clone Quickstart Code

Clone the quickstart code from the Diagrid Labs GitHub repository and navigate to the appropriate directory:

diagrid dev quickstart --type state --language python

After the command executes successfully, the CLI will output the contents of your newly created project including an App ID called order-app and a Diagrid KV Store called kvstore.

4

Install Dependencies and Run

The diagrid dev run command creates your Catalyst project (if needed), provisions resources (App IDs, Components, Diagrid KV Store service), configures environment variables, and launches your application using the dapr multi-app run file.

Install .NET dependencies:

dotnet restore

Run the application:

diagrid dev run -f dev-python-state.yaml --project dev-python-state
5

Call the State API

With the quickstart running, test the State API using curl or the REST Client extension with the test.rest file.

Store state

Open a new terminal and execute the following curl command to save a state item to the Diagrid KV store:

curl -i -X POST http://localhost:5001/order -H "Content-Type: application/json" -d '{"orderId":1}'

save state

Retrieve state

Confirm the state item was saved successfully by retrieving the state:

curl -i -X GET http://localhost:5001/order/1

You can also view the stored item using the Diagrid KV Store data explorer:

data explorer

Delete state

Delete the state item using the below command:

curl -i -X DELETE http://localhost:5001/order/1

After running the above commands, the local app logs should indicate an order was saved, retrieved and deleted.

To stop the application:

diagrid dev stop
6

Clean Up ResourcesOptional

If you are not going to continue to use this application, delete the app ID:

diagrid appid delete order-app

To delete the entire Catalyst project, including the managed infrastructure resources:

diagrid project delete dev-python-state  # or dev-csharp-state, dev-js-state, dev-java-state