CoreRPC alternatives and similar packages
Based on the "HTTP" category.
Alternatively, view CoreRPC alternatives based on common mentions on social networks and blogs.
-
Refit
The automatic type-safe REST library for .NET Core, Xamarin and .NET. Heavily inspired by Square's Retrofit library, Refit turns your REST API into a live interface. -
WebApiClient
An open source project based on the HttpClient. You only need to define the c# interface and modify the related features to invoke the client library of the remote http interface asynchronously. -
FastEndpoints
A light-weight REST API development framework for ASP.Net 6 and newer. [Moved to: https://github.com/FastEndpoints/Library] -
RestEase
Easy-to-use typesafe REST API client library for .NET Standard 1.1 and .NET Framework 4.5 and higher, which is simple and customisable. Inspired by Refit -
Apizr
Refit based web api client management, but resilient (retry, connectivity, cache, auth, log, priority, etc...) -
Lib.Net.Http.WebPush
Lib.Net.Http.WebPush is a library which provides a Web Push Protocol based client for Push Service. -
Fluxzy.Core
Fast and fully streamed Man-On-The-Middle engine and a CLI app to intercept, record and alter HTTP/1.1, H2, websocket traffic over plain or secure channels. -
Lib.Net.Http.EncryptedContentEncoding
Lib.Net.Http.EncryptedContentEncoding is a library which adds Encrypted Content-Encoding (aes128gcm) support to HttpClient
InfluxDB - Power Real-Time Data Analytics at Scale
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of CoreRPC or a related project?
README
CoreRPC
Extensible library for WCF-like RPC targeting netstandard1.3 (compatible with .NET, .NET Framework, Mono and .NET Core). TCP transport supports connection pooling and multiplexing requests within one connection, infrastructure itself allows multiple "services" to be hosted inside one host. You may define your own handler factory or "routing" mechanism. Serializer (JSON.NET is used by default) is also easy to replace.
NuGet Packages
Install the following package into your projects.
Target | CoreRPC Package | NuGet |
---|---|---|
Standalone | CoreRPC | |
ASP .NET Core | CoreRPC.AspNetCore |
Protocol Definition
Put an interface into your shared library and reference it from both client and server apps:
public interface IService
{
Task<string> Foo(int bar);
}
Server App
Implement the declared interface:
public class Service : IService
{
public Task<string> Foo(int bar)
{
return Task.FromResult(bar.ToString());
}
}
Configure the router and start your server using either TCP, HTTP, or Named Pipes:
// Configure the router.
var router = new DefaultTargetSelector();
router.Register<IService, Service>();
var engine = new Engine().CreateRequestHandler(router);
// Use Named Pipes.
new NamedPipeHost(engine).StartListening("AwesomePipeName");
// Or, use HTTP (ASP.NET Core).
public void Configure(IApplicationBuilder app, IHostingEnvironment env) {
app.UseCoreRPC("/rpc", engine);
}
Client App
Use the protocol your server uses, and call remote procedures!
// Use HTTP.
var transport = new HttpClientTransport("http://example.com/rpc");
// Or, use Named Pipes.
var transport = new NamedPipeClientTransport("AwesomePipeName");
// Crete the proxy and call remote procedures!
var proxy = new Engine().CreateProxy<IService>(transport);
var res = await proxy.Foo(1);
Assembly Scanning
CoreRPC.AspNetCore
package supports automatic RPC registration. All you need is to mark your classes with the RegisterRpc
attribute. CoreRPC will discover and register classes marked with that attribute automatically once you add a call to .UseCoreRpc()
to your app builder:
// Implement the shared interface.
[RegisterRpc(typeof(IService))]
public class Service : IService
{
public Task<string> Foo(int bar)
{
return Task.FromResult(bar.ToString());
}
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
// CoreRPC will register the class maked with RegisterRpc automatically.
app.UseCoreRpc("/rpc");
}
You can override the built-in assembly scanning engine and a few other options if necessary:
// This may be useful when writing integrational tests, etc.
app.UseCoreRpc("/rpc", config =>
{
// By default, CoreRPC uses camel case resolver, but you can override that.
config.JsonSerializer.ContractResolver = new DefaultContractResolver();
config.RpcTypeResolver = () =>
{
// Skip abstract classes and types not marked with [RegisterRpc] (default behavior).
var assembly = Assembly.GetAssembly(typeof(Startup));
return assembly.DefinedTypes
.Where(type => !type.IsAbstract || type.IsInterface &&
type.GetCustomAttribute<RegisterRpcAttribute>() != null);
};
// You can also add a custom RPC method call interceptor.
config.Interceptors.Add(new MyMethodCallInterceptor());
});
RPC Interception
If you need to intercept RPCs, implement the IMethodCallInterceptor
interface and register it:
// The simplest interceptor that apparently does nothing.
public class Interceptor : IMethodCallInterceptor
{
public Task<object> Intercept(MethodCall call, object context, Func<Task<object>> invoke)
{
// Add your custom logic here.
return invoke();
}
}
// Register the method call interceptor.
app.UseCoreRpc("/rpc", config => config.Interceptors.Add(new Interceptor()));
TypeScript API Generation
CoreRPC provides you an ability to generate TypeScript code for your server-side API.
// Store the generated TS code somewhere, e.g. save it to 'api.ts' file.
// Putting such C# code into your Startup.cs file might be a good idea.
string generatedCode = AspNetCoreRpcTypescriptGenerator.GenerateCode(types, config =>
{
config.ApiFieldNamingPolicy = type => type.Replace("Rpc", string.Empty);
config.DtoFieldNamingPolicy = TypescriptGenerationOptions.ToCamelCase;
});
Usage Examples
See tests for more examples.
*Note that all licence references and agreements mentioned in the CoreRPC README section above
are relevant to that project's source code only.