pnpm install
docker compose up -d
pnpm start
curl --request POST \
--url http://localhost:4242/workflows \
--header 'Content-Type: application/json'
curl --request POST \
--url http://localhost:4242/workflows/o8bls8 \
--header 'Content-Type: application/json' \
--data '{ "type": "SUBMIT" }'
curl --request GET \
--url http://localhost:4242/workflows/o8bls8 \
--header 'Content-Type: application/json'
curl --request POST \
--url http://localhost:4242/workflows/o8bls8 \
--header 'Content-Type: application/json' \
--data '{ "type": "APPROVE" }'
curl --request GET \
--url http://localhost:4242/workflows/o8bls8 \
--header 'Content-Type: application/json'
node -r esbuild-register race-condition.ts 0 100
This is a simple workflow engine built with:
- XState v5
- TypeScript
- Express
This is a modified version of the express-workflow project that shows how to implement state hydration in the actorService.ts
file.
It also uses a more complex machine with guards, actions, and parallel states configured.
NOTE: This project is not production-ready and is intended for educational purposes.
MongoDB should be configured with a database named creditCheck
.
Use docker compose up -d to have a database with creditCheck included.
We recommend installing the MongoDB Compass app to view the contents of your database while you run this project.
Add the connection string to the DB client in the actorService.ts
file by updating this line:
const uri = "<your mongo uri here>";
pnpm install
pnpm start
Creates a new workflow instance.
curl -X POST http://localhost:4242/workflows
Example response:
201 - Created
{
{"message":"New worflow created successfully","workflowId":"uzkjyy"}
}
200 - OK
Sends an event to a workflow instance.
# Replace :id with the workflow ID; e.g. http://localhost:4242/workflows/7ky252
# the body should be JSON
curl -X POST http://localhost:4242/workflows/:id -d '{"type": "Submit", "SSN": "123456789", "lastName": "Bauman", "firstName": "Gavin"}' -H "Content-Type: application/json"
Gets the current state of a workflow instance.
curl -X GET http://localhost:4242/workflows/:id
Initialize workflow:
curl --request POST \
--url http://localhost:4242/workflows
-H "Content-Type: application/json"
Send Event (send SUBMIT then APPROVE - can have saving issue at either event):
curl --request POST \
--url http://localhost:4242/workflows/vcrtyr \
--data '{"type": "APPROVE"}'
-H "Content-Type: application/json"
Get Saved Status:
curl --request GET \
--url http://localhost:4242/workflows/vcrtyr
-H "Content-Type: application/json"