ores.cpp.http-route.route_header
Table of Contents
The class declaration for one entity's HTTP route unit. The unit owns one route per derived verb, and exposes the one entry point a hand-written per-component aggregator calls to install them.
Two substitutions place the output, and both come from {component}, the
short component name without the product prefix. The part directory is
ores.http.<component>, so a trading entity writes into
projects/ores.http/trading/. The include path keeps the shared
ores.http/ prefix the part's own include root uses, so a unit moves between
the adapter parts without an edit to any #include.
The header names no protocol type. The canonical request and response are used only inside the handler bodies, so the header stays a declaration of the surface the aggregator sees and the protocol include lands in the source beside the code that names it.
1. Template
The full template source. Edit here and re-tangle with
compass build --direct tangle_codegen_templates to regenerate
library/templates/cpp_http_route_header.hpp.mustache.
{{! GENERATED FILE — tangled from projects/ores.codegen/library/templates/ores.cpp.http-route.route_header.org. Edit the org source. }}
{{{cpp_license}}}
{{#domain_entity}}
#ifndef ORES_HTTP_ROUTES_{{entity_singular_upper}}_ROUTES_HPP
#define ORES_HTTP_ROUTES_{{entity_singular_upper}}_ROUTES_HPP
#include "ores.http.api/domain/http_request.hpp"
#include "ores.http.api/domain/http_response.hpp"
#include "ores.http.api/net/router.hpp"
#include "ores.http.api/openapi/endpoint_registry.hpp"
#include "ores.logging/make_logger.hpp"
#include "ores.nats/service/nats_client.hpp"
#include <boost/asio/awaitable.hpp>
#include <memory>
#include <string_view>
namespace ores::http::routes::{{component}} {
/**
* @brief Every verb asset {{entity_plural}} answer, as one HTTP route each.
*
* The unit is the entity's own derivation addressed over HTTP, so a verb the
* model gains appears as a route without an edit here and a verb it loses
* takes its route with it. What each route carries follows from its shape: a
* paged read is addressed by its query, a write by its canonical request
* body, and everything else by the key in its path.
*
* The unit authorises nobody. The service's generated handler owns the
* entity's permission, and the caller's own token travels with every request
* this unit forwards.
*/
class {{entity_singular}}_routes {
private:
inline static std::string_view logger_name =
"ores.http.routes.{{component}}.{{entity_singular}}_routes";
static auto& lg() {
using namespace ores::logging;
static auto instance = make_logger(logger_name);
return instance;
}
public:
/**
* @brief Register the {{entity_plural}} routes.
*
* @param session The client every route forwards on. The caller's token
* is taken from each HTTP request and delegated on it, so the unit holds
* no authorisation state of its own.
*/
static void register_routes(std::shared_ptr<ores::http::net::router> router,
std::shared_ptr<ores::http::openapi::endpoint_registry> registry,
ores::nats::service::nats_client& session);
{{#http_route.routes}}
/**
* @brief {{method_upper}} {{pattern}} — {{summary}}.
*/
static boost::asio::awaitable<ores::http::domain::http_response>
handle_{{identifier}}(const ores::http::domain::http_request& req,
ores::nats::service::nats_client& session);
{{/http_route.routes}}
};
}
#endif
{{/domain_entity}}
2. See also
- Parent facet: ores.cpp.http-route.
- Sibling archetype: ores.cpp.http-route.route_implementation.