Simple JSON-RPC protocol implementation based on ASP.NET Core project.
git clone https://github.com/giosil/NetJsonRpc.git
dotnet publish NetJsonRpc/NetJsonRpc.csproj -c Release -o published
cd NetJsonRpc
- Starting dotnet in the root folder you get http 404 on launch index.htmldotnet published/NetJsonRpc.dll
docker build -t netjsonrpc .
docker run --rm -it -p 5000:80 --name=netjsonrpc_test netjsonrpc
dotnet build
dotnet test
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using NetJsonRpc.Protocol;
using NetJsonRpc.Services;
namespace NetJsonRpc.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class RpcController : ControllerBase
{
public RpcController(ILoggerFactory loggerFactory)
{
// Initialize RPC
RPC.AddHanlder("TEST", new TestService());
RPC.AddHanlder("DBMS", new DBService());
}
// GET api/rpc
[HttpGet]
public ActionResult<string> Get()
{
return "JSON-RPC";
}
// POST api/rpc
[HttpPost]
public ActionResult<IDictionary<string, object>> Post([FromBody] IDictionary<string, object> request)
{
RPCRequest req = new RPCRequest(request);
RPCResponse res = RPC.Invoke(req);
return res.GetDictionary();
}
}
}