An ability to work with customized versions of the http-parser library is added in this version. It makes possible handling of non-standard HTTP-methods.
Let's assume we have to write a REST-service that reacts to non-standard methods ENCODE and DECODE. With RESTinio-0.5 we can do the following:
* fork http-parser library and modify that fork with the addition on ENCODE and DECODE methods. As a result, we'll have HTTP_ENCODE and HTTP_DECODE constants;
* define two constants of type http_method_id_t in our code:
constexpr const restinio::http_method_id_t http_encode{HTTP_ENCODE, "ENCODE"};
constexpr const restinio::http_method_id_t http_decode{HTTP_DECODE, "DECODE"};
* define a type with just one static method from_nodejs inside:
struct my_http_mehods_mapping {
inline static constexpr restinio::http_method_id_t
from_nodejs(int method_code) noexcept {
switch(method_code) {
case HTTP_ENCODE: return http_encode;
case HTTP_DECODE: return http_decode;
default:
return restinio::default_http_methods_t::from_nodejs(method_code);
}
}
};
* specify the name of that type in our HTTP-server's traits:
struct my_server_traits : public restinio::default_traits_t {
using http_methods_mapper_t = my_http_methods_mapping;
};
After that, we can use http_encode and http_decode working with RESTinio. For example:
auto make_request_handler() {
auto router = std::make_unique< restinio::router::express_router_t<> >();
router->add_handler(http_encode, "/data", [](auto req, auto params) {...});
router->add_handler(http_decode, "/data", [](auto req, auto params) {...});
...
return router;
}
NOTE. During the implementation of this new feature, the type http_method_t has been removed from RESTinio, and new type http_method_id_t has been introduced. So if you use http_method_t, you have to modify your code when switching to RESTinio-0.5.
Some old things which were marked as "deprecated" earlier were removed from RESTinio.
Documentation with helpful information is
here.