![]() |
zeep::http::rest_controller — class that helps with handling REST requests
// In header: <zeep/http/rest-controller.hpp> class rest_controller : public { public: // member classes/structs/unions template<typename Callback, > struct mount_point { }; template<typename ControllerType, typename Result, Args> struct mount_point<> : public { // types typedef ; typedef ; typedef ; typedef ; // construct/copy/destruct template< Names> (, , rest_controller *, , ); // public member functions (parameter_pack &, reply &); template<typename ResultType, typename ArgsTuple, = > (, reply &); template<typename ResultType, typename ArgsTuple, = > (, reply &); template<typename ResultType, typename ArgsTuple, = > (, reply &); (reply &, ); (reply &, zeep::json::element &&); template<typename T> (reply &, ); template< I> (parameter_pack &, ); (parameter_pack &, , ); (parameter_pack &, , ); file_param (parameter_pack &, , file_param); file_param > (parameter_pack &, , file_param >); json::element (parameter_pack &, , json::element); template<typename T> (parameter_pack &, , ); (parameter_pack &, , ); template<typename T, = > (parameter_pack &, , ); template<typename T, = > (parameter_pack &, , ); template<typename T, = > (parameter_pack &, , ); // public data members static N; m_callback; m_names; }; // abstract base class for mount points struct mount_point_base { // construct/copy/destruct (, ); ~(); // public member functions (parameter_pack &, reply &) = ; // public data members m_path; m_method; m_rx; m_path_params; }; // helper class for pulling parameter values out of the request struct parameter_pack { // construct/copy/destruct (request &); // public member functions () ; () ; () ; file_param () ; file_param > () ; // public data members request & m_req; param > m_path_parameters; }; // construct/copy/destruct (); ~(); // public member functions (request &, reply &); // protected member functions template<typename Callback, ArgNames> (, , , ); template<typename Callback, ArgNames> (, , ); template<typename Sig, ArgNames> (, , ); template<typename Sig, ArgNames> (, , ); template<typename Sig, ArgNames> (, , ); };
This controller will handle REST requests. (See https://restfulapi.net/ for more info on REST)
To use this, create a subclass and add some methods that should be exposed. Then map these methods on a path that optionally contains parameter values.
See the chapter on REST controllers in the documention for more information.
rest_controller
protected member functionstemplate<typename Callback, ArgNames> ( mountPoint, method, callback, names);map mountPoint in URI space to callback and map the arguments in this callback to parameters passed with names
The mountPoint parameter is the local part of the mount point. It can contain parameters enclosed in curly brackets.
For example, say we need a REST call to get the status of shoppingcart where the browser will send: `GET /ajax/cart/1234/status`
Our callback will look like this, for a class my_ajax_handler constructed with prefixPath /ajax
:
Then we mount this callback like this:
The number of names of the paramers specified should be equal to the number of actual arguments for the callback, otherwise the compiler will complain.
Arguments not found in the path will be fetched from the payload in case of a POST or from the URI parameters otherwise.
template<typename Callback, ArgNames> ( mountPoint, callback, names);map a POST to mountPoint in URI space to callback and map the arguments in this callback to parameters passed with names
template<typename Sig, ArgNames> ( mountPoint, callback, names);map a PUT to mountPoint in URI space to callback and map the arguments in this callback to parameters passed with names
template<typename Sig, ArgNames> ( mountPoint, callback, names);map a GET to mountPoint in URI space to callback and map the arguments in this callback to parameters passed with names
template<typename Sig, ArgNames> ( mountPoint, callback, names);map a DELETE to mountPoint in URI space to callback and map the arguments in this callback to parameters passed with names