Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/apache/openwhisk-runtime-dotnet

Apache OpenWhisk Runtime .Net supports Apache OpenWhisk functions written in .Net languages
https://github.com/apache/openwhisk-runtime-dotnet

apache cloud docker dot-net dotnet faas functions functions-as-a-service openwhisk openwhisk-runtime serverless serverless-architectures serverless-functions

Last synced: about 1 month ago
JSON representation

Apache OpenWhisk Runtime .Net supports Apache OpenWhisk functions written in .Net languages

Awesome Lists containing this project

README

        

# Apache OpenWhisk runtimes for .NET

[![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0)
[![Continuous Integration](https://github.com/apache/openwhisk-runtime-dotnet/actions/workflows/ci.yaml/badge.svg)](https://github.com/apache/openwhisk-runtime-dotnet/actions/workflows/ci.yaml)

## Give it a try today

Create a C# project called Apache.OpenWhisk.Example.Dotnet:

```bash
dotnet new classlib -n Apache.OpenWhisk.Example.Dotnet -lang "C#"
cd Apache.OpenWhisk.Example.Dotnet
```

Install the [Newtonsoft.Json](https://www.newtonsoft.com/json) NuGet package as follows:

```bash
dotnet add package Newtonsoft.Json -v 13.0.1
```

Now create a file called `Hello.cs` with the following content:

```csharp
using System;
using Newtonsoft.Json.Linq;

namespace Apache.OpenWhisk.Example.Dotnet
{
public class Hello
{
public JObject Main(JObject args)
{
string name = "stranger";
if (args.ContainsKey("name")) {
name = args["name"].ToString();
}
JObject message = new JObject();
message.Add("greeting", new JValue($"Hello, {name}!"));
return (message);
}
}
}
```
Publish the project as follows:

```bash
dotnet publish -c Release -o out
```

Zip the published files as follows:

```bash
cd out
zip -r -0 helloDotNet.zip *
```

Create the action

```bash
wsk action update helloDotNet helloDotNet.zip --main Apache.OpenWhisk.Example.Dotnet::Apache.OpenWhisk.Example.Dotnet.Hello::Main --kind dotnet:6.0
```

For the return result, not only support `dictionary` but also support `array`

So a very simple `hello array` function would be:

```csharp
using System;
using Newtonsoft.Json.Linq;

namespace Apache.OpenWhisk.Tests.Dotnet
{
public class HelloArray
{
public JArray Main(JObject args)
{
JArray jarray = new JArray();
jarray.Add("a");
jarray.Add("b");
return (jarray);
}
}
}
```

And support array result for sequence action as well, the first action's array result can be used as next action's input parameter.

So the function can be:

```csharp
using System;
using Newtonsoft.Json.Linq;

namespace Apache.OpenWhisk.Tests.Dotnet
{
public class HelloPassArrayParam
{
public JArray Main(JArray args)
{
return (args);
}
}
}
```

## Changelogs

- [.NET 6.0 CHANGELOG.md](core/net6.0/CHANGELOG.md)

## Quick Start Guides

- [.NET Core 6.0](core/net6.0/QUICKSTART.md)

# License

[Apache 2.0](LICENSE.txt)