Quack.Api 1.3.5

Install-Package Quack.Api -Version 1.3.5
dotnet add package Quack.Api --version 1.3.5
<PackageReference Include="Quack.Api" Version="1.3.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Quack.Api --version 1.3.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Quack.Api, 1.3.5"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. 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.3.5

// Install Quack.Api as a Cake Tool
#tool nuget:?package=Quack.Api&version=1.3.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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);
}

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.3.5 0 12/5/2021
1.3.4 142 9/11/2021
1.3.3 114 9/10/2021
1.3.2 145 6/18/2021
1.3.1 156 5/27/2021
1.3.0 120 5/24/2021
1.2.2 94 4/23/2021
1.2.1 160 4/17/2021
1.2.0 154 4/17/2021
1.1.0 90 4/14/2021
1.0.0 95 4/9/2021

Updated dependencies