Binding
The frontend communicates with the backend using a binding system. The frontend sends a message to the backend, and the backend responds with a message. The frontend then displays the message in the webview. A default example of this binding system is shown in the image above where the frontend interacts with the 'greet' binding.
Greet Binding
NOTE
The following code snippets show how the Default Tempalte greet binding is implemented in the C++ backend and also across the supported Vue frontend frameworks. For the frontend, the code snippets just show the relevant parts of the code that interact with the greet binding. They do not show the entire frontend code. For full examples of the frontend code for each framework, refer to the Celaris Templates Repository.
Celaris c = Celaris();
// Example of a binding that hooks the frontend greet function
c.bind("greet", [&](const std::string &req) -> std::string
{
json response;
auto jsonreq = json::parse(req);
if (jsonreq.size() != 1)
{
response["message"] = "Invalid request";
}
else
{
response["message"] = "Hello " + jsonreq[0].get<std::string>() + ", You have been greeted from C++";
}
return response.dump(); });
c.run();