This article introduces developers to the capabilities of FaaS for all supported runtimes: .NET, Go, Java, Node.js, and Python. For each runtime, we provide examples of three abstract functions of ascending levels of complexity:
using System;using System.Collections.Generic;using System.Threading.Tasks;// main method will be module.handlerpublic class module{ public Task<object> handler(Dictionary<string, object> k8Event, Dictionary<string, string> k8Context) { return Task.FromResult<object>("hello world"); }}
using System;using System.Collections.Generic;using YamlDotNet.Serialization;using System.Threading.Tasks;public class module{ public Task<object> handler(Dictionary<string, object> k8Event, Dictionary<string, string> k8Context) { var person = new Person() { Name = "Michael J. Fox", Age = 56 }; var serializer = new SerializerBuilder().Build(); return Task.FromResult<object>(serializer.Serialize(person)); // yaml }}public class Person{ public string Name { get; set; } public int Age { get; set; }}
To build this function, specify the dependencies in the .csproj format:
For all runtimes, you can find the request object in the event map field. Each language has a unique type. For C#, it’s HttpRequest from Microsoft.AspNetCore.Http.
Copy
Ask AI
using System;using System.Collections.Generic;using System.Threading.Tasks;using Microsoft.AspNetCore.Http;// main method module.handlerpublic class module{ public Task<object> handler(Dictionary<string, object> k8sEvent, Dictionary<string, string> k8Context) { var extension = (Dictionary<string, object>)k8sEvent["extension"]; HttpRequest request = (HttpRequest)extension["request"]; Console.WriteLine(request); if (request.Method == "POST") { return Task.FromResult<object>(create()); } else if (request.Method == "GET") { return Task.FromResult<object>(get()); } else { return Task.FromResult<object>("Method not allowed"); } } public string create() { return "Creating something on POST request"; } public string get() { return "Getting something on GET request"; }}
package io.kubeless;import java.util.HashMap;import org.joda.time.LocalTime;public class Module { public String handler(HashMap<String, Object> event, HashMap<String, String> context) { LocalTime currentTime = new LocalTime(); return "Hello world! Current local time is: " + currentTime; }}