Skip to content
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

Routing madness #11

Closed
trullock opened this issue Feb 20, 2024 · 2 comments
Closed

Routing madness #11

trullock opened this issue Feb 20, 2024 · 2 comments
Labels
question Further information is requested

Comments

@trullock
Copy link

if you do

server.on("/foo", HTTP_GET, [] (AsyncWebServerRequest *req) {
    // A
});
server.on("/foo/bar", HTTP_GET, [] (AsyncWebServerRequest *req) {
    // B
});

And then make a request to "/foo/bar", you hit the first handler.

AsyncCallbackWebHandler and AsyncCallbackJsonWebHandler both have this in them:

if(_uri.length() && (_uri != request->url() && !request->url().startsWith(_uri+"/")))
      return false;

Which is the offending line. Why on earth is it doing a startsWith?

We have regex and wildcard routing capabilities. I've not rummaged in Git history, is this a hangover from a previous, less powerful routing feature?

@mathieucarbou
Copy link
Owner

This is how the original library work - you can look at its more complete documentation.
This won't change in this fork, which is mainly there for bug fixes and maintenance purposes.

You need to place your most specific handlers first, and the most generic one after, when they both work on the same HTTP method.

My guess it to allow some features to work in the framework.
It also allow to be compliant with REST API standard with just a simple handler:

GET /api/user/1234
PUT /api/user/1234
etc

Where the handler would only be in GET /api/user and then the handler would read the user id from the URI.

@trullock
Copy link
Author

Thanks for the reply

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants