XState + Durable Entities = 🚀
- Ensure you have all the prerequisites satisfied in the Azure Functions documentation.
- Install the
DurableTask
extension:func extensions install --package Microsoft.Azure.WebJobs.Extensions.DurableTask -v 2.3.1
- Copy the
local.settings.template.json
file and rename tolocal.settings.json
, and configure theAzureWebJobsStorage
value to be a valid storage connection string. See the documentation for more info
- Run
npm install
to install the required dependencies. - Hit F5 or run
npm start
to start the function.
In this sample, the DonutEntity
is controlled by the following statechart:
View this statechart on XState Viz
To send an event to an entity:
Open up an API client, such as Postman, and POST
a JSON event object, which is an object that contains a { type: "someEventType" }
property, to http://localhost:7071/api/DonutTrigger?id=<ENTITY ID>
:
POST http://localhost:7071/api/DonutTrigger?id=donut1
{
"type": "NEXT"
}
Or using curl
:
curl -d '{"type": "NEXT"}' -H "Content-Type: application/json" -X POST http://localhost:7071/api/DonutTrigger?id=donut1
The text response should be similar to:
Event "NEXT" sent to entity "donut1".
To view the state of an entity:
In the same API client, send a GET
request to http://localhost:7071/api/DonutTrigger?id=<ENTITY ID>
GET http://localhost:7071/api/DonutTrigger?id=donut1
Or using curl
:
curl http://localhost:7071/api/DonutTrigger?id=donut1
Example response:
{
"entityExists": true,
"entityState": {
...
"value": {
"directions": "makeDough"
},
...
"event": {
"type": "NEXT"
},
...
}
}