Skip to content

meenzen/Zammad.Client.SystemTextJson

 
 

Repository files navigation

GitHub codecov NuGet NuGet

Zammad.Client.SystemTextJson

A hard fork of Zammad.Client with support for System.Text.Json instead of Newtonsoft.Json.

This library provides a .NET client for interacting with the Zammad helpdesk system API.

Installation

dotnet add package Zammad.Client.SystemTextJson

Usage

Basic example:

var httpClient = new HttpClient();
var client = new ZammadClient(
    httpClient,
    Options.Create(new ZammadOptions
    {
        BaseUrl = new Uri("https://zammad.example.com/"),
        Token = "your_token_here",
    })
);

var user = await client.GetUserMeAsync();
Console.WriteLine($"Signed in as {user.FirstName} {user.LastName} ({user.Email})");

Dependency Injection

Install the extensions package:

dotnet add package Zammad.Client.SystemTextJson.Extensions

Configure the client:

builder.Services.AddZammadClient(options =>
{
    options.BaseUrl = new Uri("https://zammad.example.com/");
    options.Token = "your_token_here";
});

Alternatively, use a configuration section:

builder.Services.AddZammadClient(builder.Configuration.GetSection("Zammad"));

Then inject the client:

public class MyService(IZammadClient client)
{
    public async Task DoSomething()
     {
         var user = await client.GetUserMeAsync();
         Console.WriteLine($"Signed in as {user.FirstName} {user.LastName} ({user.Email})");
     }
}

HttpClient Customization

The AddZammadClient method returns an IHttpClientBuilder, allowing further customization of the underlying HttpClient. For example, to add a resilience handler:

dotnet add package Microsoft.Extensions.Http.Resilience
builder.Services.AddZammadClient(builder.Configuration.GetSection("Zammad"))
    .AddStandardResilienceHandler();

This configuration will automatically handle transipent errors, making your application more robust.

Contributing

Pull requests are welcome. Please use Conventional Commits to keep commit messages consistent.

Please consider adding tests for any new features or bug fixes.

Acknowledgements

License

Distributed under the Apache License 2.0. See LICENSE for more information.

About

Modern Zammad Client Library for .NET

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Languages

  • C# 90.6%
  • Shell 9.4%