rest_rpc_old

Now this project has been changed to https://github.com/topcpporg/rest_rpc

Stars
65

rest_rpc https://github.com/topcpporg/rest_rpc

topcpp modern, simple, easy to use rpc framework. ##Motivation c++ RPCprotobufthrift

  • DSLmodel
  • model
  • DSL
  • APIAPISDKSDK

rest_rpcrest_rpc

  • DSL
  • API
  • model
  • modern(c++14),

##Getting started

##Tutorial

rpc serveraddtranslate

#include <string>
#include "server.hpp"

int add(int a, int b)
{
	return a + b;
}

struct messenger
{
	std::string translate(const std::string& orignal)
	{
		std::string temp = orignal;
		for (auto & c : temp) c = toupper(c);
		return temp;
	}
};

int main()
{
	server s(9000, std::thread::hardware_concurrency()); 

	s.register_handler("add", &add);
	messenger m;
	s.register_handler("translate", &messenger::translate, &m);

	s.run();
	return 0;
}

rpc serverrpcrest rpc

rpc clientrpc

#include "client_proxy.hpp"

int main()
{
	try
	{
		boost::asio::io_service io_service;
		client_proxy client(io_service);
		client.connect("127.0.0.1", "9000");
		
		std::string result = client.call("translate", "test");
		//{"code":0,"result":"TEST"}

		io_service.run();
	}
	catch (const std::exception& e)
	{
		std::cerr << "Exception: " << e.what() << std::endl;
	}

	return 0;
}

clientjson

template<typename T>
struct response_msg
{
	int code;
	T result; //json.
};

jsontranslate RPCKapok

DeSerializer dr;
dr.Parse(result);

response_msg<std::string> response = {};
dr.Deserialize(response);
std::cout<<respnse.result<<std::endl; //will output upper word.

callgithub

rest rpc2rpc

enum result_code
{
	OK = 0,
	FAIL = 1,
	EXCEPTION = 2,
	ARGUMENT_EXCEPTION = 3
};
RPCresponse_msg<T>json
RCP

    template<typename T>
    void handle_result(const char* result)
    {
    	DeSerializer dr;
    	dr.Parse(result);
    	Document& doc = dr.GetDocument();
    	doc.Parse(result);

    	if (doc[CODE].GetInt() == result_code::OK)
    	{
    		response_msg<T> response = {};
    		dr.Deserialize(response);
    		std::cout << response.result << std::endl;
    	}
    	else
    	{
    		//maybe exception, output the exception message.
    		std::cout << doc[RESULT].GetString() << std::endl;
    	}
    }

##Missuses rest rpc

  • rpc

  • rpcMETA

      template<typename T>
      struct response_msg
      {
      	int code;
      	T result;
      	META(code, result);
      };
    

    Kapok

  • base6416codec.

  • buf8192

  • RPC

##Dependencies

##FAQ

  • RPCRPC

    c++RPCthriftprotobufDSLIDLRPCRPCrest rpcstar

  • RPC

    rest rpcasiorest rpc(qps10w)

  • rest rpc

  • rest rpc

    c++(purecpp.org), githubissue.rest rpcrest rpcrest rpc

  • rest rpc

Related Projects