Skip to content

Latest commit

 

History

History
78 lines (55 loc) · 2.11 KB

writing-a-dotnetcore-function.md

File metadata and controls

78 lines (55 loc) · 2.11 KB

Writing a .NET Core 2 Function

This guide uses practical examples to guide you through the process of writing serverless .NET Core functions.

In this document

Overview

The .NET Core runtime allows function developers to create a function using .NET Core 2. This guide walks you through the scenario.

Deploy a .NET Core function

This example guides you through the steps for deploying a .NET Core code that reverses the event's body. To implement this, you call reverser and pass an input;

Create a /tmp/nuclio-dotnetcore-script/reverser.cs file with the following code:

// @nuclio.configure
//
// function.yaml:
//   spec:
//     runtime: dotnetcore
//     handler: nuclio:reverser

using System;
using Nuclio.Sdk;

public class nuclio
{
  public string reverser(Context context, Event eventBase)
  {
    var charArray = eventBase.GetBody().ToCharArray();
    Array.Reverse(charArray);
    return new string(charArray);
  }
}

The function configuration needs to include the following:

  1. runtime - set to dotnetcore.
  2. handler - set to the name of the class and the name of the method . In this example, the handler is nuclio:reverser.

Run the following command to deploy the function with the nuctl nuclio CLI:

Note: if you're not running on top of Kubernetes, pass the --platform local option to nuctl.

nuctl deploy -p /tmp/nuclio-dotnetcore-script/reverser.cs reverser

You can also remove the settings from reverser.cs and run the following command:

nuctl deploy -p /tmp/nuclio-dotnetcore-script/reverser.cs --runtime dotnetcore --handler nuclio:reverser reverser

And now, use the nuctl CLI to invoke the function:

nuctl invoke reverser -m POST -b reverse-me

> Response headers:
Date = Sun, 03 Dec 2017 12:53:51 GMT
Content-Type = text/plain; charset=utf-8
Content-Length = 10
Server = nuclio

> Response body:
em-esrever

See also