Quack.Api
1.4.1
dotnet add package Quack.Api --version 1.4.1
NuGet\Install-Package Quack.Api -Version 1.4.1
<PackageReference Include="Quack.Api" Version="1.4.1" />
<PackageVersion Include="Quack.Api" Version="1.4.1" />
<PackageReference Include="Quack.Api" />
paket add Quack.Api --version 1.4.1
#r "nuget: Quack.Api, 1.4.1"
#:package Quack.Api@1.4.1
#addin nuget:?package=Quack.Api&version=1.4.1
#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 | Versions 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.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. |
-
.NETCoreApp 3.1
- Shadow.Quack.Json (>= 1.4.7)
-
.NETFramework 4.6.1
- Shadow.Quack.Json (>= 1.4.7)
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 | 2,198 | 4/5/2022 |
| 1.4.0 | 569 | 1/30/2022 |
| 1.3.7 | 568 | 1/30/2022 |
| 1.3.6 | 603 | 1/20/2022 |
| 1.3.5 | 439 | 12/5/2021 |
| 1.3.4 | 582 | 9/11/2021 |
| 1.3.3 | 488 | 9/10/2021 |
| 1.3.2 | 499 | 6/18/2021 |
| 1.3.1 | 516 | 5/27/2021 |
| 1.3.0 | 506 | 5/24/2021 |
| 1.2.2 | 447 | 4/23/2021 |
| 1.2.1 | 498 | 4/17/2021 |
| 1.2.0 | 520 | 4/17/2021 |
| 1.1.0 | 450 | 4/14/2021 |
| 1.0.0 | 475 | 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