Skip to main content

Echo Method

This is a tutorial on how to create a BACKND Function that returns the string requested by the BACKND SDK method using the BACKND Function as-is, and debug, build, and deploy using the Backend Function development tool.
In order to proceed with the tutorial, the BACKND Function development tool and BACKND Function project template must be installed.


  1. Use the BackendFunction template to create a new project.
    Refer to the Create Project documentation to create a new project.

  1. Write a Function method as follows.
public Stream Function(Stream stream, ILambdaContext context)
{
try
{
// Initialize BACKND Function API
Backend.Initialize(ref stream);
}
catch(Exception e)
{
// When BACKND Function API initialization fails
return ReturnErrorObject("initialize " + e.ToString());
}

// Check whether the value key exists in `content` in debugConfig.json or in `Param` passed as a parameter value when calling InvokeFunction
// in the BACKND SDK.
if(Backend.HasKey("value") == false)
{
return ReturnErrorObject("value key is not exist");
}

// The `Param` sent as a parameter value when calling InvokeFunction in the BACKND SDK or `content` in debugConfig.json
// can be accessed using Backend.Content.
return Backend.StringToStream(Backend.Content["value"].ToString());
}

  1. Configure the debugConfig.json file.
    Refer to the Debugging documentation for information on debugging settings.
    At this time, set the content in debugConfig.json as follows:

debugConfig.json

{
...
"content": {
"value": "HelloWorld!" // Replace HelloWorld! with the desired string.
}
}

  1. Perform debugging.
    If the result is as shown in the figure below, the process is successful.

  1. Configure BACKND CLI config.json.
    Enter backend config in cmd, and save after entering the following in the open notepad(excluding authKey).
{
"account": {
"authKey": "BACKND Function authentication key issued from BACKND Console"
},
"projectInfo": {
// Enter the absolute path of the project created by the developer.
// The path must be separated by \\ so that the CLI can recognize it normally.
// ex) C:\\work\\funcSet
"projectPath": "Project path",
// Enter the name of the project created by the developer.
"csprojName": "BackendFunction.csproj",
"binName": "publish.zip"
},
"functionName": "echoFunction",
"description": "A method that performs an echo function."
}

  1. Build the project using BACKND CLI.
    Enter the backend build command in cmd.
    Please refer to the Build documentation.

  1. Deploy the build output to the server using BACKND CLI.
    Enter the backend deploy command in cmd.
    Please refer to the Deploy documentation.

  1. Check if the deployment has been carried out correctly in BACKND Console.

9. Check if the deployed method returns correctly by calling the BACKND SDK method in Unity.

In the BACKND SDK, try calling the method as shown below, and check if it returns correctly.

Param param = new Param();
param.Add("value", "HelloWorld!");

var bro = Backend.BFunc.InvokeFunction("echoFunction", param);

If successful, bro is returned as below.
statusCode : 200
message : Success returnValue : {"result":"HelloWorld!"}