Skip to content

Husky931/durable-entities-xstate

 
 

Repository files navigation

durable-entities-xstate

XState + Durable Entities = 🚀

Quick Start

  1. Run npm install to install the required dependencies.
  2. Hit F5 or run npm start to start the function.

Interacting with the State Machine

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"
    },
    ...
  }
}

About

XState + Durable Entities = 🚀

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • TypeScript 100.0%