Skip to content

moira-alert/client-csharp

Repository files navigation

C# API Client for Moira NuGet

If you're new here, better check out our main README.

Overview

This API client was generated by the OpenAPI Generator tool.

Our current documentation is available on SwaggerHub.

Installation

Install with dotnet CLI:

dotnet add package Moira.ApiClient

Getting started

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Moira.ApiClient.Api;
using Moira.ApiClient.Extensions;

namespace YourNamespace
{
    public static class Program
    {
        public static async Task Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();
            var triggerApi = host.Services.GetRequiredService<ITriggerApi>();
            var apiResponse = await triggerApi.GetAllTriggersAsync();
            var model = apiResponse.Ok();
        }

        private static IHostBuilder CreateHostBuilder(string[] args)
        {
            return Host.CreateDefaultBuilder(args)
                .ConfigureMoiraApiClient((context, services, options) =>
                {
                    options.ConfigureJsonOptions(jsonOptions =>
                    {
                        // your custom converters if any
                    });

                    options.AddMoiraApiClientHttpClients(client =>
                    {
                        // client configuration
                    }, builder =>
                    {
                        // add whatever middleware you prefer
                        builder
                            .AddRetryPolicy(2)
                            .AddTimeoutPolicy(TimeSpan.FromSeconds(5))
                            .AddCircuitBreakerPolicy(10, TimeSpan.FromSeconds(30));
                    });
                });
        }
    }
}

Questions

  • What about HttpRequest failures and retries? Configure Polly in the IHttpClientBuilder
  • How are tokens used? Tokens are provided by a TokenProvider class. The default is RateLimitProvider which will perform client side rate limiting. Other providers can be used with the UseProvider method.
  • Does an HttpRequest throw an error when the server response is not Ok? It depends on how you made the request. If the return type is ApiResponse no error will be thrown, though the Content property will be null. StatusCode and ReasonPhrase will contain information about the error. If the return type is T, then it will throw. If the return type is TOrDefault, it will return null.
  • How do I validate requests and process responses? Use the provided On and After partial methods in the api classes.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages