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

Prerequisites
Before you proceed, ensure you have the following prereqs installed.
- Python
- .NET
- JavaScript
- Java
Log in to Catalyst
Authenticate to Diagrid Catalyst using the following command:
diagrid login
Confirm your organization and user details are correct:
diagrid whoami
Clone Quickstart Code
Clone the quickstart code from the Diagrid Labs GitHub repository and navigate to the appropriate directory:
- Python
- .NET
- JavaScript
- Java
diagrid dev quickstart --type state --language python
diagrid dev quickstart --type state --language csharp
diagrid dev quickstart --type state --language javascript
diagrid dev quickstart --type state --language java
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.
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.
- Python
- .NET
- JavaScript
- Java
Create and activate a Python virtual environment:
python -m venv venv
source venv/bin/activate # MacOS/Linux
# Or: venv\Scripts\activate # Windows
Windows users: Use venv\Scripts\Activate.ps1 (PowerShell) or venv\Scripts\activate.bat (Command Prompt). Use conda, pipenv, or your preferred tool if desired.
Install dependencies:
pip install -r requirements.txt
Install .NET dependencies:
dotnet restore
Install Node dependencies:
npm install
Install Maven dependencies:
mvn clean install
Run the application:
- Python
- .NET
- JavaScript
- Java
diagrid dev run -f dev-python-state.yaml --project dev-python-state
diagrid dev run -f dev-csharp-state.yaml --project dev-csharp-state
diagrid dev run -f dev-js-state.yaml --project dev-js-state
diagrid dev run -f dev-java-state.yaml --project dev-java-state
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}'

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:

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
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