Quack.Api 1.4.1

dotnet add package Quack.Api --version 1.4.1
NuGet\Install-Package Quack.Api -Version 1.4.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Quack.Api" Version="1.4.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Quack.Api --version 1.4.1
#r "nuget: Quack.Api, 1.4.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Quack.Api as a Cake Addin
#addin nuget:?package=Quack.Api&version=1.4.1

// Install Quack.Api as a Cake Tool
#tool nuget:?package=Quack.Api&version=1.4.1

Quack API

Using the both Shadow Quack base library and Shadow Quack JSON this package includes custom implementation of JsonConverter and JsonConvertorFactory, that wrap the JSON proxy, to allow the use of Interfaces as return and parameter types in ASP .Net API calls.

by adding the QuackInterfaceConverterFactory to the Converters list,

services.AddControllers().AddJsonOptions(opts =>
    {
        opts.JsonSerializerOptions.Converters.Add(new QuackInterfaceConverterFactory());
    });

You can use interfaces as the inputs and outputs to your API calls without needing to do anything else!

WeatherForecastController.cs

using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Shadow.Quack;

namespace Example.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class WeatherForecastController : ControllerBase
    {
        private static readonly string[] Summaries = new[]
        {
            "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
        };

        private readonly ILogger<WeatherForecastController> _logger;

        public WeatherForecastController(ILogger<WeatherForecastController> logger)
        {
            _logger = logger;
        }

        [HttpGet]
        public IEnumerable<IWeatherForecast> Get()
        {
            var rng = new Random();
            return Enumerable.Range(1, 5).Select(index => Duck.Implement<IWeatherForecast>(new 
            {
                Date = DateTime.Now.AddDays(index),
                TemperatureC = rng.Next(-20, 55),
                Summary = Summaries[rng.Next(Summaries.Length)]
            }))
            .ToArray();
        }
    }
}

IWeatherForecast.cs

using System;

namespace Example
{
    public interface IWeatherForecast
    {
        DateTime Date { get; }
        int TemperatureC { get; }
        int TemperatureF { get; }
        string Summary { get; }
    }
}

The above shows using this with the Weather Forecast example API, note the Get() method now has only abstract interface types in the declaration; public IEnumerable<IWeatherForecast> Get() and the creation of the return value is done using Duck.Implement<T>(object source).

Interfaces can be used as the types for API inputs too, for example

[HttpPost]
public bool Post(IPostData data)
{
    return Process(data);
}

Options

Quack.Api.Options.Default returns a new JsonSerializerOptions instance with the QuackInterfaceConverterFactory already added.

JsonSerializerOptions .AddInterfaceConverters() extension which adds the QuackInterfaceConverterFactory to the converters, returns the JsonSerializerOptions instance for pipeline usage.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
.NET Framework net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.4.1 1,643 4/5/2022
1.4.0 417 1/30/2022
1.3.7 395 1/30/2022
1.3.6 422 1/20/2022
1.3.5 288 12/5/2021
1.3.4 426 9/11/2021
1.3.3 342 9/10/2021
1.3.2 344 6/18/2021
1.3.1 360 5/27/2021
1.3.0 326 5/24/2021
1.2.2 292 4/23/2021
1.2.1 342 4/17/2021
1.2.0 363 4/17/2021
1.1.0 289 4/14/2021
1.0.0 318 4/9/2021

* Added Options.Default; returns a new JsonSerializerOptions instance with the QuackInterfaceConverterFactory already added
* JsonSerializerOptions .AddInterfaceConverters() extension which adds the QuackInterfaceConverterFactory to the converters