From a6d3e04cc18b6d4f9948fd3796f84a2d293e61fc Mon Sep 17 00:00:00 2001 From: Marc Duiker Date: Tue, 22 Apr 2025 10:32:17 +0200 Subject: [PATCH] Add cURL Signed-off-by: Marc Duiker --- .../Activities/RequestApproval.cs | 2 +- .../external-system-interaction/README.md | 35 ++++++++++++++----- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/tutorials/workflow/csharp/external-system-interaction/ExternalEvents/Activities/RequestApproval.cs b/tutorials/workflow/csharp/external-system-interaction/ExternalEvents/Activities/RequestApproval.cs index 81d114d9..43d50186 100644 --- a/tutorials/workflow/csharp/external-system-interaction/ExternalEvents/Activities/RequestApproval.cs +++ b/tutorials/workflow/csharp/external-system-interaction/ExternalEvents/Activities/RequestApproval.cs @@ -7,7 +7,7 @@ internal sealed class RequestApproval : WorkflowActivity { public override Task RunAsync(WorkflowActivityContext context, Order order) { - Console.WriteLine($"{nameof(RequestApproval)}: Received order: {order.Id}."); + Console.WriteLine($"{nameof(RequestApproval)}: Request approval for order: {order.Id}."); // Imagine an approval request being sent to another system return Task.FromResult(true); } diff --git a/tutorials/workflow/csharp/external-system-interaction/README.md b/tutorials/workflow/csharp/external-system-interaction/README.md index 4529ff45..da2f97b4 100644 --- a/tutorials/workflow/csharp/external-system-interaction/README.md +++ b/tutorials/workflow/csharp/external-system-interaction/README.md @@ -4,7 +4,7 @@ This tutorial demonstrates how to author a workflow where the workflow will wait ## Inspect the code -Open the `ExternalEventsWorkflow.cs` file in the `tutorials/workflow/csharp/external-system-interaction/ExternalEvents` folder. This file contains the definition for the workflow. It is an order workflow that requests an external approval if the order has a total price greater than 250 dollars. +Open the `ExternalEventsWorkflow.cs` file in the `tutorials/workflow/csharp/external-system-interaction/ExternalEvents` folder. This file contains the definition for the workflow. It is an order workflow that requests an external approval if the order has a total price greater than 250 dollars. ```mermaid graph LR @@ -61,7 +61,14 @@ graph LR ``` -4. Use the POST request in the [`externalevents.http`](./externalevents.http) file to start the workflow. +4. Use the POST request in the [`externalevents.http`](./externalevents.http) file to start the workflow, or use this cURL command: + + ```bash + curl --request POST \ + --url http://localhost:5258/start \ + --header 'content-type: application/json' \ + --data '{"id": "b7dd836b-e913-4446-9912-d400befebec5","description": "Rubber ducks","quantity": 100,"totalPrice": 500}' + ``` The input for the workflow is an `Order` object: @@ -74,17 +81,28 @@ graph LR } ``` -5. Use the GET request in the [`externalevents.http`](./externalevents.http) file to get the status of the workflow. +5. Use the GET request in the [`externalevents.http`](./externalevents.http) file to get the status of the workflow, or use this cURL command: + + ```bash + curl --request GET --url http://localhost:3558/v1.0/workflows/dapr/b7dd836b-e913-4446-9912-d400befebec5 + ``` The workflow should still be running since it is waiting for an external event. The app logs should look similar to the following: ``` - == APP - externalevents == Received order: Order { Id = ef4c1a3b-7eb5-4fc3-90e9-3bd606044b3a, Description = Rubber ducks, Quantity = 100, TotalPrice = 500 }. + == APP - externalevents == Received order: Order { Id = b7dd836b-e913-4446-9912-d400befebec5, Description = Rubber ducks, Quantity = 100, TotalPrice = 500 }. ``` -6. Use the POST request in the [`externalevents.http`](./externalevents.http) file to send an `approval-event` to the workflow. +6. Use the POST request in the [`externalevents.http`](./externalevents.http) file to send an `approval-event` to the workflow, or use this cURL command: + + ```bash + curl -i --request POST \ + --url http://localhost:3558/v1.0/workflows/dapr/b7dd836b-e913-4446-9912-d400befebec5/raiseEvent/approval-event \ + --header 'content-type: application/json' \ + --data '{"OrderId": "b7dd836b-e913-4446-9912-d400befebec5","IsApproved": true}' + ``` The payload for the event is an `ApprovalStatus` object: @@ -94,16 +112,15 @@ graph LR "IsApproved": true } ``` -*The workflow will only wait for the external approval event for 2 minutes before timing out. In this case you will need to start a new order workflow instance.* + + *The workflow will only wait for the external approval event for 2 minutes before timing out. In this case you will need to start a new order workflow instance.* 7. Again use the GET request in the [`externalevents.http`](./externalevents.http) file to get the status of the workflow. The workflow should now be completed. The expected serialized output of the workflow is: ```txt - "\"Order 15b18587-86d6-4cb2-8496-8d60ab350a43 has been approved.\"" + "\"Order b7dd836b-e913-4446-9912-d400befebec5 has been approved.\"" ``` - *The Order ID is generated when making the request and is different each time.* - 8. Stop the Dapr Multi-App run process by pressing `Ctrl+C`.