Comments (2)
Hi!
Sorry for the delay with the response, I needed some time to think.
I suppose you want to implement some handler that will accept all incoming requests, do something and then delegate the processing of a request to ordinary RESTinio mechanisms (like express-router).
If so then I'm afraid the only way to do that is to write your own router
object. This object will accept all requests, do what you need and then will call some of RESTinio's standard router. For example, it could be something like that:
class interceptor_router {
// This will be the actual router.
restinio::router::express_router_t actual_router_;
...
public:
// Add a request handler to actual_router.
void http_get(restinio::string_view_t path, restinio::router::express_request_handler_t handler) {
actual_router_.http_get(path, std::move(handler));
}
void http_post(restinio::string_view_t path, restinio::router::express_request_handler_t handler) {
actual_router_.http_post(path, std::move(handler));
}
...
// This operator will be called by RESTinio on arrival of a new request.
restinio::request_handling_status_t operator()(restinio::request_handle_t req) const
{
... // Do what you want.
// Now the actual router can be called.
actual_handler_(std::move(req));
}
...
};
Then you can parametrize RESTinio's server traits by this type:
struct my_traits_t : public restinio::default_traits_t {
using request_handler_t = interceptor_router;
};
...
run( restinio::on_thread_pool<my_traits_t>(4)... );
PS. It seems that you can derive interceptor_router
from restinio::router::express_router_t
:
class interceptor_router : public restinio::router::express_router_t {
using base_type = restinio::router::express_router_t;
...
public:
// This operator will be called by RESTinio on arrival of a new request.
restinio::request_handling_status_t operator()(restinio::request_handle_t req) const
{
... // Do what you want.
// Now the actual router can be called.
base_type::operator()(std::move(req));
}
...
};
In that case you don't need to redefine methods like http_get
and http_put
in your router type.
from restinio.
Thanks so much, your code snippet it works flawlessly.
from restinio.
Related Issues (20)
- Use of unmaintained repository Clara HOT 1
- The installed file include/restinio/so5/so_timer_manager.hpp uncludes the header so_5/all.hpp that isn't installed HOT 1
- Need for a base class? HOT 2
- Partial reception of big request bodies HOT 1
- Cannot use in CLang C++ 20 HOT 5
- Set handle_request_timeout per route HOT 3
- clara (used by test suite) abandoned upstream HOT 4
- automatically free buffer when request is done HOT 1
- Compilation of express router tests fails on VC++ 19 (VisualStudio 2022) HOT 1
- HTTPS not working
- <algorithm> isn't included in easy_parser.hpp
- Any chance std::fopen() call can be changed to std::fopen_s()? HOT 14
- New overload for sendfile and std::filesystem::path?
- CMake configure fails when using boost asio via find HOT 9
- vcpkg should have a variant with RESTinio+Boost.Asio HOT 1
- There should be operator<< for http_status_code_t
- static_if_impl has to be replaced with if constexpr
- There is no such type as generic_request_handler_t
- build system regression: RESTINIO_USE_EXTERNAL_SOBJECTIZER no longer available HOT 3
- allow using catch2 from system HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from restinio.