Boost C++ Libraries

PrevUpHomeNext

Function template with_session

boost::taar::handler::with_session — Bind a keyed context to a handler.

Synopsis

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


template<typename Key, typename Context, typename KeyExtractor, 
         typename Inner> 
  auto with_session(context_store< Key, Context > & store, KeyExtractor key, 
                    session_policy policy, Inner inner);

Description

taar::context_store<std::string, cart> carts {std::chrono::minutes {30}};

session.register_request_handler(
    method == http::verb::post && target == "/cart/items",
    taar::handler::with_session(carts,
        taar::handler::session_key::cookie("sid"),
        taar::handler::session_policy::create_if_missing,
        taar::handler::rest(&add_item, json_body_arg())));   // add_item(cart&, json::value)

Parameters:

store

The context_store that owns the keyed contexts. Must outlive the session.

key

A key extractor from the session_key namespace.

policy

What to do when the key is absent or unknown.

inner

The handler to run with the keyed context in scope.


PrevUpHomeNext