-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Different URLs call different get requests #10
Comments
Hi @Alanscut , Thank you for highlighting the feature, it's a good point so I'll add the demo for same . |
Thanks, that's great! Could you please offer a simple demo here 😄 ? |
Hi @Alanscut I was looking at the code , http_listener listener(baseURI) only supports the single url so best approach would be writing a router middleware that will route the requests according to paths. So eventually the current handler will act as a router that will redirect the requests to the specified handler. pseudo logic for same would be and where . suppose you want to route 2 get requests as you mentioned is comment. void handler::handle_get(http_request message){
}. // current this code will act as ` void route(http_request message);` of myRouter class below.
==================myRouter.h====
class myRouter{
private: HashContainer<url,handler> routingData;
...
public :
void registerHandler(string path_OR_pathRegex, myHandler handler); //this will register the paths with handler , you can call it multiple times so register multiple paths.
void registerDefaultHandler( myHandler handler); //register for undefined paths.
void route(http_request message); //this will route to specific handler registered by `registerHandler` method for a path.
...
}
class myHandler{
void handle_get1(http_request message);
void handle_get2(http_request message);
}
// now register your logic handler like this.
myRouter.register("/seconde",&myhandler::handle_get2);
myRouter.register("/first",&myhandler::handle_get1);
Also this can be extend to domain name based routing.ActionItems:
|
Dear Meena, thanks for your patience and friendly instructions, I'll try it later. 👍 |
Hi @Alanscut , Thanks , I've noted the action Item and will complete this asap but If you implement the router in generic way or find any good library to do such job in the mean time, please let me know and feel free to ask for any help. I'm always ready to help and learn. Thanks, |
Is your feature request related to a problem? Please describe.
Thank you very much for your project, it helps me a lot since I'm a green hander for C++. According to your demo, I could easily create a server which has 4 different requests, and we visit them through the same url
http://localhost:34568
with different request types(GET, POST ..).But if I want to create another
GET request
likehttp://localhost:34568/rest/api
, I have no idea how to do it.Describe the solution you'd like
if you don't mind, please add an example code in this project.
Additional context
what I want to do is that: when visit
http://localhost:34568/first
, then excute handle_get1, and when visithttp://localhost:34568/second
, then excute handle_get2.handler.cpp
The text was updated successfully, but these errors were encountered: