rpc ~master

An RPC library


To use this package, run the following command in your project's root directory:

rpc

DUB Package Build Status

An rpc library aimed to be protocol agnostic. It's based on automatic interface implementation.

It currently support:

It use vibed as HTTP and TCP driver.

It also use vibe.data.json for json serialization.

Quick start with dub

"dependencies": {
	"rpc": "*"
}

Basic usage

An example showing how to fetch the last Ethereum block number using the rpc api.

import std.stdio;
import rpc.protocol.json;


interface IEthereumApi
{
    string eth_blockNumber();
}

void main()
{
	enum EthNode = "https://eth-mainnet.alchemyapi.io/jsonrpc/-vPGIFwUyjlMRF9beTLXiGQUK6Nf3k8z";
	auto eth = new HttpJsonRpcAutoClient!IEthereumApi(EthNode);

	writeln(eth.eth_blockNumber());
}

The server for the above example could be implemented like this:

import rpc.protocol.json;


interface IEthereumApi
{
	string eth_blockNumber();
}

class EthereumServer : IEthereumApi
{
	override string eth_blockNumber()
	{
		return "42";
	}
}

void main()
{
	import vibe.http.router;
	
	enum EthNode = "https://eth-mainnet.alchemyapi.io/jsonrpc/-vPGIFwUyjlMRF9beTLXiGQUK6Nf3k8z";
	auto eth = new HttpJsonRpcAutoClient!IEthereumApi(EthNode);

	writeln(eth.eth_blockNumber());
	
	auto router = new URLRouter();
	auto server = new HttpJsonRpcServer!int(router, "/my_endpoint");
	server.registerInterface!IEthereumApi(new EthereumServer());
	listenHTTP("127.0.0.1:8080", router);
}

You can browse the examples folder for more information.

Authors:
  • Eliott Dumeix
Dependencies:
vibe-d:data, vibe-d:utils, vibe-d:core, autointf, vibe-d:http
Versions:
1.1.0 2018-Sep-06
~master 2019-Apr-11
Show all 2 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 0 downloads this month

  • 13 downloads total

Score:
0.0
Short URL:
rpc.dub.pm