Getting Started
The minimal example for displaying some content contains the following steps:
- Creating a BoomackClient instance with a configuration
- Building and sending a DisplayRequest
- Disposing the BoomackClient instance, e. g. with the
using
directive
In this example both levels of error handling are demonstrated.
The try-catch-block handles errors on the network level.
The if block, checking the Success
property of the response,
handles errors on the application level.
Basic Style
using Boomack.Client;
using Boomack.Client.Model;
// prepare the client configuration
var config = new ClientConfiguration()
{
ServerUrl = new Uri("http://127.0.0.1:3000"),
Token = null,
};
// instantiate the client with the prepared configuration
using var client = new BoomackClient(config);
// prepare the display request
var request = new DisplayRequest()
{
Panel = "default",
Text = "Hello World!",
Type = "text/plain",
};
try
{
// pass the prepared request
var response = await client.Display(request);
if (!response.Success)
{
Console.Error.WriteLine("HTTP Response Status {0}", response.StatusCode);
Console.Error.WriteLine(response.Content);
}
}
catch (HttpRequestException e)
{
Console.Error.WriteLine("HTTP Request Failed with: {0}", e.Message);
}
Fluent Style
using Boomack.Client;
// use the fluent API to configure and instantiate the client
using var client = BoomackClient.Builder
.For("http://127.0.0.1:3000")
.WithToken(null)
.BuildClient();
try
{
// use the fluent API to build and send the request
var response = await client.Display(builder => builder
.Target(panel: "default")
.Text("Hello World!"));
if (!response.Success)
{
Console.Error.WriteLine("HTTP Response Status {0}", response.StatusCode);
Console.Error.WriteLine(response.Content);
}
}
catch (HttpRequestException e)
{
Console.Error.WriteLine("HTTP Request Failed with: {0}", e.Message);
}
Next: Client Configuration