c-sharp
c-sharp copied to clipboard
Request response style api support
Simple Usage (Builder Pattern)
var result = await pubnub.Publish()
.Message("Hello World")
.Channel("my-channel")
.ExecuteAsync();
Advanced Usage (Request/Response Overload)
var response = await pubnub.Publish(new PublishRequest
{
Message = new { text = "Hello", metadata = "value" },
Channel = "my-channel",
StoreInHistory = true,
Ttl = 24,
Metadata = new Dictionary<string, object> { { "type", "notification" } },
UsePost = true
});
Error Handling
try
{
var response = await pubnub.Publish(request);
Console.WriteLine($"Published with timetoken: {response.Timetoken}");
}
catch (ArgumentException ex)
{
Console.WriteLine($"Validation error: {ex.Message}");
}
catch (PNException ex)
{
Console.WriteLine($"PubNub error: {ex.Message}");
}
:tada: Snyk checks have passed. No issues have been found so far.
:white_check_mark: security/snyk check is complete. No issues have been found. (View Details)
:white_check_mark: license/snyk check is complete. No issues have been found. (View Details)