SingleApi 1.0.1
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package SingleApi --version 1.0.1
NuGet\Install-Package SingleApi -Version 1.0.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="SingleApi" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SingleApi --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SingleApi, 1.0.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 SingleApi as a Cake Addin #addin nuget:?package=SingleApi&version=1.0.1 // Install SingleApi as a Cake Tool #tool nuget:?package=SingleApi&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
SingleApi
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 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: .NET 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
Product | Versions 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.2 | 73 | 11/16/2024 |
1.5.0 | 158 | 1/12/2024 |
1.4.0 | 597 | 11/16/2022 |
1.3.0 | 338 | 11/9/2022 |
1.2.3 | 378 | 10/29/2022 |
1.2.1 | 389 | 10/28/2022 |
1.2.0 | 366 | 10/27/2022 |
1.1.6 | 418 | 9/29/2022 |
1.1.5 | 439 | 9/22/2022 |
1.1.4 | 421 | 9/21/2022 |
1.1.3 | 441 | 9/21/2022 |
1.1.2 | 427 | 9/20/2022 |
1.1.1 | 406 | 9/20/2022 |
1.1.0 | 419 | 9/19/2022 |
1.0.1 | 431 | 9/12/2022 |
1.0.0 | 415 | 9/11/2022 |