SingleApi 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package SingleApi --version 1.0.0
NuGet\Install-Package SingleApi -Version 1.0.0
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="SingleApi" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SingleApi --version 1.0.0
#r "nuget: SingleApi, 1.0.0"
#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 SingleApi as a Cake Addin
#addin nuget:?package=SingleApi&version=1.0.0

// Install SingleApi as a Cake Tool
#tool nuget:?package=SingleApi&version=1.0.0

SingleApi NuGet version

Single/generic WebApi handler (mediator ready)

Features

  • Mediator ready
  • Generics support

Example 1: SingleApi with MediatR

.NET CLI

dotnet new web --name "SingleApiExample"
cd SingleApiExample
dotnet add package SingleApi
dotnet add package MediatR.Extensions.Microsoft.DependencyInjection

Change Program.cs

using MediatR;
using System.Reflection;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddMediatR(Assembly.GetExecutingAssembly());

var app = builder.Build();

app.MapSingleApi("sapi", 
    // invoke the MediatR
    x => x.ServiceProvider.GetRequiredService<IMediator>().Send(x.Data, x.CancellationToken),
    // assemblies for type resolving
    Assembly.GetExecutingAssembly()); 

app.Run();

Example project...

Example 2: Request/Response

// Request
GET /sapi/Ping?data={"Message":"TEST"}

or

POST /sapi/Ping
{"Message":"TEST"}


// Response
{"message":"TEST PONG"}

Example 3: Generic types

app.MapSingleApi("sapi", 
    // for simplicity, return the received data
    x => Task.FromResult(x.Data), 
    // existing generic types will suffice for this example
    typeof(List<>).Assembly, typeof(int).Assembly); 
// Request #1: equivalent of List<String>
POST /sapi/List(String)
["text1","text2","text3"]


// Request #2: equivalent of Dictionary<string,int?[]>
POST /sapi/Dictionary(String,Array(Nullable(Int32)))
{"key1":[555,null,777]}

Example 4: SingleApi.Client

.NET CLI

dotnet new console --name "SapiClientExample"
cd SapiClientExample
dotnet add package SingleApi.Client

Program.cs:

using SingleApi.Client;

// create client
using var sapi = new SapiClient("https://localhost:7263/sapi");

// send request
var response = await sapi.Send(new Ping { Message = "TEST" });

Console.WriteLine(response?.Message);


//// Console output:
// TEST PONG

Example project...

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

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.5.0 114 1/12/2024
1.4.0 571 11/16/2022
1.3.0 313 11/9/2022
1.2.3 348 10/29/2022
1.2.1 362 10/28/2022
1.2.0 343 10/27/2022
1.1.6 391 9/29/2022
1.1.5 415 9/22/2022
1.1.4 393 9/21/2022
1.1.3 409 9/21/2022
1.1.2 399 9/20/2022
1.1.1 379 9/20/2022
1.1.0 394 9/19/2022
1.0.1 402 9/12/2022
1.0.0 391 9/11/2022