You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Would it be possible to to extend the template specialization in order to add custom methods and/or default behavior to the constructor?
There's a lot of boiler plate between create_response() and done(), for example:
restinio::request_handling_status_tedit::operator()(const restinio::request_handle_t &req, restinio::router::route_params_t params) {
auto &user = list_.get(restinio::cast_to<int>(params["id"]));
user_management::user_modifier(user).apply(nlohmann::json::parse(req->body()));
return req->create_response()
.append_header(restinio::http_field::access_control_allow_origin, "*") // Added on every request// More CORS Headers...
.append_header(restinio::http_field::content_type, "application/json") // Always true// Date, Last-Modified, ETag, Accept-Patch ... etc...
.set_body(nlohmann::json(user).dump()) // This is a typical JSON API, it would be nice to have handlers for my custom types
.done();
}
Response builders use inheritance only to avoid code duplication. Because of that response_builder_t<T> is not designed to be used in class hierarchies.
I think your case can be solved by using your own response-builder class like that:
Would it be possible to to extend the template specialization in order to add custom methods and/or default behavior to the constructor?
There's a lot of boiler plate between
create_response()
anddone()
, for example:Now it would be very easy to have...
What I would love to have...
This begs the question
restinio/dev/restinio/message_builders.hpp
Lines 257 to 259 in a6a07d1
The text was updated successfully, but these errors were encountered: