---
title: llarp/rpc/rpc_request.hpp

---

# llarp/rpc/rpc_request.hpp



## Namespaces

| Name           |
| -------------- |
| **[llarp](Namespaces/namespacellarp.md)** <br>[crypto.hpp] |
| **[llarp::rpc](Namespaces/namespacellarp_1_1rpc.md)**  |




## Source code

```cpp
#pragma once

#include "rpc_server.hpp"
#include "rpc_request_decorators.hpp"
#include "rpc_request_definitions.hpp"
#include "rpc_request_parser.hpp"
#include "json_bt.hpp"
#include <string_view>
#include <llarp/config/config.hpp>
#include <oxenmq/oxenmq.h>
#include <oxenmq/address.h>
#include <oxen/log/omq_logger.hpp>


namespace llarp::rpc {

  using nlohmann::json;

  template <typename RPC>
  auto make_invoke() {
    return [](oxenmq::Message& m, RPCServer& server) {
      EndpointHandler<RPC> handler{server, m.send_later()};
      auto& rpc = handler.rpc;
      
      if (m.data.size() > 1)
        m.send_reply(CreateJSONError("Bad Request: RPC requests must have at most one data part (received " + std::to_string(m.data.size()) + ")"));

      std::string_view request;
      if (!m.data.empty())
        request = m.data[0];

      // parsing input as bt or json
      //    hand off to parse_request (overloaded versions)
      try {
          if (request.front() == 'd') { // Looks like a bt dict
            rpc.set_bt();
            parse_request(rpc, oxenc::bt_dict_consumer{request});
          }
          else
            parse_request(rpc, m.data.empty() ? nlohmann::json::object() : nlohmann::json::parse(m.data));
      } catch (const std::exception& e) {
        m.send_reply(CreateJSONError("Failed to parse request parameters: "s + e.what()));
      }
      
      
      if (std::is_base_of_v<Deferred, RPC>)
        server.m_Router.loop()->call_soon(std::move(handler));
      else
        handler();
      
    };
  }

} // namespace llarp::rpc
```


-------------------------------

Updated on 2023-01-18 at 23:51:38 +0000
