commanet.Http.RPC
1.1.1
dotnet add package commanet.Http.RPC --version 1.1.1
NuGet\Install-Package commanet.Http.RPC -Version 1.1.1
<PackageReference Include="commanet.Http.RPC" Version="1.1.1" />
paket add commanet.Http.RPC --version 1.1.1
#r "nuget: commanet.Http.RPC, 1.1.1"
// Install commanet.Http.RPC as a Cake Addin
#addin nuget:?package=commanet.Http.RPC&version=1.1.1
// Install commanet.Http.RPC as a Cake Tool
#tool nuget:?package=commanet.Http.RPC&version=1.1.1
commanet.Http.RPC
Library for using HTTP APIs. Hide all details of implementation for HTTP Client/Server. Let developer to be focused on business logic development with standard c# classes.
Consists from:
- Common Library (commanet.Http.RPC.Common)
- Server Side Library (commanet.Http.RPC.Server)
- Client Side Library (commanet.Http.RPC.Client)
Server and Client parts can be used separately in different applications or together if app plays both roles: Provides API for external programs and use external API(s) provided by others.
Getting Started
using commanet.Http.RPC;
...
// Define common interface
// Can do it in server side application or, if supposed
// to use client in DotNet, better create separate assembly
// shared between client and server implementations
[HTTPRPCInterface] // Attribute it to let know RPC Engine
IMyAPI = interface
{
string HelloHttpRPCWorld(();
}
Server Side
using commanet.Http.RPC;
...
// Define Class Implements our Interface
public class MyServerImplementation : IMyAPI
{
string HelloHttpRPCWorld(){return "Hello World!!!"};
}
...
// Start server
static int Main(string[] args)
{
var server = new HTTPRPCServer("localhost",5010);
server.Run();
server.WaitForShutdown();
// Notice that classes implements HTTPRPC interfaces will be
// discovered automatically - you do not need to
// create instances in code
}
Client Side
using commanet.Http.RPC;
// Start server
static int Main(string[] args)
{
var client = HTTPRPCClient.Client<IMyAPI>(new Uri("http://localhost:5010/api"));
var result=client.HelloHttpRPCWorld();
Console.WriteLine(result);
}
API Interface Attributes
- HTTPRPCInterface - used on interface definition level
- HTTPHandler - used on inteface method definition level
All attributes declared in commanet.Http.RPC.Common assembly is shared between server and client sides.
HTTPRPCInterface Attribute Parameters
Base Path
string BasePath = "api"
Defines base path to HTTP API calls. Full URL to API call will be :
http://<yourserver>[:port]/<BasePath>/<MethodName>
AddInterfaceNameToPath
bool AddInterfaceNameToPath = false
If parameter is true then in URL will be added interface name. It is useful in case if application implements multiple interfaces. Leading 'I' character in interface name will be suppressed. Full URL for calling method will be:
http://<yourserver>[:port]/<BasePath>/<InterfaceName>/<MethodName>
Notice that all names in url will be converted into low case.
HTTPHandler Attribute Parameters
Path
HttpMethods Method = HttpMethods.Get
Defines HTTP method to be used
ParametersIn
public enum ParamsPlacedIn {URLPath, Query, Body}
ParamsPlacedIn ParametersIn = ParamsPlacedIn.URLPath
Defines how call parameters will be passed to server.
Pass parameters in URL path (call arguments by its position):
http://server/api/method/value1/value2
Pass parameters in URL Query part. Arguments can be passed by name or by position:
http://server/api/method?parameter1=value1¶meter2=value2
http://server/api/method?value1&value2
Notice that calls generated by commanet.Http.RPC.Client library, in case of choosing Query parameters location will use named parameters. Server side automatically discovers way used and supports all of them. Third party client applications can use both URL and QUERY parameters locations.
CacheMilliseconds
int CacheMilliseconds = 0
Optionally (if > 0) defines time for caching call results. Useful for performance tuning for high-loaded apps.
HTTP API Interface Method Restrictions
Output method parameters are not supported.
All types used as input parameters and results are to be serializable into JSON.
Types tested and confirmed as supported:
- int/uint
- long/ulong
- double
- float
- string
- DateTime
- c# Classes with published properties All published properties should be JSON serializable.
- byte[] Used for binary data transfer. see data size limitations description below
Client Timeouts
Client timouts available in HTTPRPCClient static public properties.
Timout | Default Value [bytes] |
---|---|
WaitResponseTimeoutMs | 30000 (milliseconds) |
ReadContentTimeoutMs | 5000 (milliseconds) |
Input/Output Data Size Limitation
For safety, amount of data to be tranfered by one HTTP request is limited on server side. URL size (used in GET reqests) is limited too. It can be changed in HTTPRPCServer class constructor input parameters.
Limit | Default Value [bytes] |
---|---|
MaxRequestLineSize | 8192 |
MaxRequestBodySize | 1048576 |
MaxRequestBufferSize | 1048576 |
MaxResponseBufferSize | 6553 |
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. |
.NET Core | netcoreapp3.1 is compatible. |
-
.NETCoreApp 3.1
- Microsoft.AspNetCore.Server.Kestrel (>= 2.2.0)
- System.Reflection.Emit (>= 4.7.0)
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.1.1 | 427 | 6/24/2020 |
Release 1