Provides .NET 6.0 API/SPI and Model Validation for the Serverless Workflow Specification
With the SDK, you can:
- Read and write workflow JSON and YAML definitions
- Programmatically build workflow definitions
- Validate workflow definitions (both schema and DSL integrity validation)
Latest Releases | Conformance to spec version |
---|---|
0.8.0.10 | v0.8 |
dotnet nuget add package ServerlessWorkflow.Sdk
services.AddServerlessWorkflow();
var workflow = WorkflowDefinition.Create("MyWorkflow", "MyWorkflow", "1.0")
.StartsWith("inject", flow =>
flow.Inject(new { username = "test", password = "123456" }))
.Then("operation", flow =>
flow.Execute("fakeApiFunctionCall", action =>
{
action.Invoke(function =>
function.WithName("fakeFunction")
.SetOperationUri(new Uri("https://fake.com/swagger.json#fake")))
.WithArgument("username", "${ .username }")
.WithArgument("password", "${ .password }");
})
.Execute("fakeEventTrigger", action =>
{
action
.Consume(e =>
e.WithName("fakeEvent")
.WithSource(new Uri("https://fakesource.com"))
.WithType("fakeType"))
.ThenProduce(e =>
e.WithName("otherEvent")
.WithSource(new Uri("https://fakesource.com"))
.WithType("fakeType"));
}))
.End()
.Build();
var reader = WorkflowReader.Create();
using(Stream stream = File.OpenRead("myWorkflow.json"))
{
var definition = reader.Read(stream, WorkflowDefinitionFormat.Json);
}
var writer = WorkflowWriter.Create();
using(Stream stream = new MemoryStream())
{
writer.Write(workflow, stream);
stream.Flush();
stream.Position = 0;
using(StreamReader reader = new StreamReader(stream))
{
var yaml = reader.ReadToEnd();
Console.WriteLine(yaml);
Console.ReadLine();
}
}
var validator = serviceProvider.GetRequiredService<IValidator<WorkflowDefinition>>();
var validationResult = validator.Validate(myWorkflow);