Yandex Cloud
Search
Discuss with expertTry it for free
  • Customer Stories
  • Documentation
  • Blog
  • All Services
  • System Status
  • Marketplace
    • Featured
    • Infrastructure & Network
    • Data Platform
    • AI for business
    • Security
    • DevOps tools
    • Serverless
    • Monitoring & Resources
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Center for Technologies and Society
    • Yandex Cloud Partner program
    • Price calculator
    • Pricing plans
  • Customer Stories
  • Documentation
  • Blog
© 2026 Direct Cursus Technology L.L.C.
Yandex Cloud Functions
  • Comparing with other Yandex Cloud services
    • Overview
      • Overview
      • Function interface
      • YcFunction interface
    • Managing dependencies
    • Request handler
    • Invocation context
    • Logging
    • Error handling
    • Using the SDK
  • Tools
  • Pricing policy
  • Access management
  • Terraform reference
  • Monitoring metrics
  • Audit Trails events
  • Public materials
  • Release notes
  • FAQ

In this article:

  • Examples
  • HTTP request structure output
  • Parsing an HTTP request
  1. Developing in .NET Core
  2. Programming model
  3. Function interface

Using the Function interface to set a handler function in C#

Written by
Yandex Cloud
Updated at May 14, 2026
  • Examples
    • HTTP request structure output
    • Parsing an HTTP request

You can set a handler function in C# without needing to inherit from SDK classes.

Warning

The handler method must be public, be named FunctionHandler, and have one input parameter.

Example of a valid handler:

public class Handler {
  public String FunctionHandler(int i) {
    return i.ToString();
  }
}

Example of an invalid handler:

// Handler should not have any type parameters
public class Handler<T> {
  public int FunctionHandler(T i) {
    return 2;
  }
}

You can use any classes as input and return types.

Note

Fields of these classes may have any access modifiers. If a field is non-public, it requires a public getter method. Otherwise, the field won't be included in the response.

ExamplesExamples

HTTP request structure outputHTTP request structure output

The following function receives a request with two fields (a string and a number) and returns a formatted string with the provided data.

Warning

To invoke the function, use the Yandex Cloud CLI or an HTTP request with the ?integration=raw parameter.

The Request.cs file:

public class Request {
  public String message { get; set; }
  public int number { get; set; }
}

The Handler.cs file:

public class Handler {
  public String FunctionHandler(Request r) {
    // at this stage, the r variable already stores the parsed request
    return $"Message is {r.message}, number is {r.number}";
  }
}

Example of input data:

{
  "message": "Hello",
  "number": 24
}

Returned string:

Message is Hello, number is 24

Parsing an HTTP requestParsing an HTTP request

The function is invoked via an HTTP request with a username, logs the request method and body, and returns a greeting.

Warning

Do not use ?integration=raw to invoke this function. If you do, the function will not get any data about the original request’s methods, headers, or parameters.

The Request.cs file:

public class Request {
  public String httpMethod { get; set; }
  public String body { get; set; }
}

The Response.cs file:

public class Response {
  public int statusCode { get; set; }
  public String body { get; set; }

  public Response(int statusCode, String body) {
    this.statusCode = statusCode;
    this.body = body;
  }
}

The Handler.cs file:

using System.Text.Json;

public class Handler {

  public Response FunctionHandler(Request r) {
    var method = r.httpMethod;
    var body = r.body;
    Console.WriteLine($"{method}, {body}");

    using var jsonDoc = JsonDocument.Parse(body);
    var root = jsonDoc.RootElement;

    // Here, the name parameter is retrieved from the request body.
    // If you do not provide it, an error will be thrown.
    var name = root.GetProperty("name").GetString(); 
    return new Response(200, $"Hello, {name}");
  }
}

Example of input data (the POST method):

{
  "name": "Anonymous"
}

The log will contain the following:

POST, { "name": "Anonymous" }

Response returned:

Hello, Anonymous

Was the article helpful?

Previous
Overview
Next
YcFunction interface
© 2026 Direct Cursus Technology L.L.C.