[Yandex Cloud documentation](../../../../index.md) > [Yandex Cloud Functions](../../../index.md) > [Developing in .NET Core](../index.md) > [Programming model](index.md) > Function interface

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

You can set a handler in C# without inheriting from [SDK](https://github.com/yandex-cloud/dotnet-sdk) classes.

{% note warning %}

The handler method must be public, named `FunctionHandler`, and have a single input parameter.

{% endnote %}

Example of a valid handler:

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

Example of an invalid handler:

```C#
// 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 info %}

Fields of these classes can have any [access modifiers](https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/access-modifiers). If a field is non-public, it requires the `getter` public method. Otherwise, the field will not be included in the response.

{% endnote %}


## Examples {#examples}

### HTTP request structure output {#http-req}

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

{% note warning %}

To invoke the function, use the [Yandex Cloud CLI](../../../concepts/function-invoke.md) or an HTTP request with the `?integration=raw` parameter.

{% endnote %}

The Request.cs file:

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

The Handler.cs file:

```C#
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:

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

Returned string:

```text
Message is Hello, number is 24
```

### Parsing an HTTP request

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

{% note 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.

{% endnote %}

The Request.cs file:

```C#
public class Request {
  public String httpMethod { get; set; }
  public String body { get; set; }
}
```

The Response.cs file:

```C#
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:

```C#
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):

```json
{
  "name": "Anonymous"
}
```

The log will contain the following:

```text
POST, { "name": "Anonymous" }
```

Response returned:

```text
Hello, Anonymous
```