Example #1
0
// --------------------- json rpc interface -----------------------
void RestServ::httpRpcRequest(mg_connection& nc, HttpMessage data)
{
    reset(data);

    StreamBuf buf{nc.send_mbuf};
    out_.rdbuf(&buf);
    out_.reset(200, "OK");
    try {
        if (uri_.empty() || uri_.top() != "rpc") {
            throw ForbiddenException{"URI not support"};
        }

        //process here
        data.data_to_arg();
        tinychain::commands cmd{data.vargv(), node_};
        Json::Value ret;
        cmd.exec(ret);

        out_<<ret.toStyledString();

    } catch (const std::exception& e) {
        out_ << e.what();
    } 

    out_.setContentLength(); 
}