Boost C++ Libraries

PrevUpHomeNext

Struct template attribute_arg

boost::taar::handler::attribute_arg — Argument provider that reads a request attribute of type T.

Synopsis

// In header: <boost/taar/handler/rest_arg.hpp>

template<typename T> 
struct attribute_arg {

  // public member functions
  std::string name() const;
  taar::result< T > 
  operator()(boost::beast::http::request_header<> const &, 
             matcher::context const &) const;
};

Description

Returns a copy of the value stored under T in boost::taar::matcher::context::attributes, typically by a session interceptor or a handler::guard check, or error::argument_not_found when none is stored, so a std::optional<T> parameter or with_default makes it optional. It reads only the matcher context, so it works in rest(...), jsonrpc::endpoint::method(...) and mcp::endpoint::tool(...) alike. It is not a client-supplied input: OpenAPI omits it, and JSON-RPC and MCP leave it out of the parameter list and the input schema.

struct principal { std::string user; };

session.register_request_handler(
    method == http::verb::get && target == "/me",
    taar::handler::rest(
        [](principal const& p) { return p.user; },
        taar::handler::attribute_arg<principal>()));

Template Parameters

  1. typename T

    The attribute type; must be copy-constructible.

attribute_arg public member functions

  1. std::string name() const;
    The attribute type's name, for diagnostics.
  2. taar::result< T > 
    operator()(boost::beast::http::request_header<> const &, 
               matcher::context const & context) const;

PrevUpHomeNext