Boost C++ Libraries

PrevUpHomeNext

Class response_builder

boost::taar::response_builder — Fluent builder around any value that response_from can convert.

Synopsis

// In header: <boost/taar/core/response_builder.hpp>


class response_builder {
public:

  // public member functions
  template<typename... ArgsType> response_builder(ArgsType &&...);
  auto && set_version(unsigned);
  auto && set_version(unsigned);
  auto && set_status(boost::beast::http::status);
  auto && set_status(boost::beast::http::status);
  auto && insert_header(std::string_view, std::string_view const &);
  auto && insert_header(std::string_view, std::string_view const &);
  auto && insert_header(boost::beast::http::field, std::string_view const &);
  auto && insert_header(boost::beast::http::field, std::string_view const &);
  auto && set_header(std::string_view, std::string_view const &);
  auto && set_header(std::string_view, std::string_view const &);
  auto && set_header(boost::beast::http::field, std::string_view const &);
  auto && set_header(boost::beast::http::field, std::string_view const &);
  boost::beast::http::message_generator get_response();
};

Description

Wrap an existing body value (a std::string, a boost::json::value, a boost::beast::http::response, etc.), then chain set_status, set_version, set_header, and insert_header on the result before consuming the final response with get_response, or returning the builder from a REST handler, in which case the conversion is automatic:

return taar::response_builder(boost::json::value{ {"ok", true} })
    .set_status(http::status::created)
    .set_header(http::field::cache_control, "no-store");

Member functions return a reference to allow chaining; the rvalue overloads return a moved-from copy so the temporary can be returned directly.

response_builder public member functions

  1. template<typename... ArgsType> response_builder(ArgsType &&... args);
    Construct around a value that response_from can convert.
  2. auto && set_version(unsigned version);
    Set the HTTP version (10 or 11).
  3. auto && set_version(unsigned version);
    Set the HTTP version (10 or 11).
  4. auto && set_status(boost::beast::http::status status);
    Set the response status.
  5. auto && set_status(boost::beast::http::status status);
    Set the response status.
  6. auto && insert_header(std::string_view name, std::string_view const & value);
    Add a header field, keeping fields of the same name.
  7. auto && insert_header(std::string_view name, std::string_view const & value);
    Add a header field, keeping fields of the same name.
  8. auto && insert_header(boost::beast::http::field field, 
                          std::string_view const & value);
    Add a header field, keeping fields of the same name.
  9. auto && insert_header(boost::beast::http::field field, 
                          std::string_view const & value);
    Add a header field, keeping fields of the same name.
  10. auto && set_header(std::string_view name, std::string_view const & value);
    Set a header field, replacing fields of the same name.
  11. auto && set_header(std::string_view name, std::string_view const & value);
    Set a header field, replacing fields of the same name.
  12. auto && set_header(boost::beast::http::field field, 
                       std::string_view const & value);
    Set a header field, replacing fields of the same name.
  13. auto && set_header(boost::beast::http::field field, 
                       std::string_view const & value);
    Set a header field, replacing fields of the same name.
  14. boost::beast::http::message_generator get_response();
    Consume the builder and return a Beast message generator.

PrevUpHomeNext