Request handler

In general request handler is a function-object receiving exactly one parameter: request handle. The function signature of the handler must be:

handler( restinio::request_handle_t req );

Each request handler receives a handle on a conrete request. restinio::request_handle_t is a alias for std::shared_ptr<restinio::request_t>. req parameters is passed by value and thus can be passed to another processing flow (that is where an async handling becomes possible).

Handler must return handling status via request_handling_status_t enum. If the handler does handle request it must return accepted value. If handler refuses to handle request it must return rejected. There are two helper functions: restinio::request_accepted() and restinio::request_rejected() for refering an itemes of the enum.

Default request handler used in traits is the following.

using default_request_handler_t =
    std::function<request_handling_status_t (request_handle_t)>;

Request structure

Let’s have a look at a very important object – restinio::request_t. It brings all the data of a given HTTP request and some internal stuff to make response mechanism work.

There are two major data pieces of request: request header and request body.

Request header can be accesed by request_t::header() function which returns a reference to restinio::http_request_header_t object. Refer to Working with http headers section for more detail on a header.

Body can be accesed by request_t::body() function which returns a reference to std::string.