Repository navigation
feat: multiple URIs per handler (setUri/addUri/clearUris) - #495
Closed
mathieucarbou wants to merge 1 commit into
Closed
mathieucarbou wants to merge 1 commit into
mathieucarbou wants to merge 1 commit into
Conversation
6 tasks done
mathieucarbou
marked this pull request as draft
October 12, 2026 16:29
mathieucarbou
force-pushed
the
feat/routing_table_v2
branch
from
October 15, 2026 12:18
320419b to
5af711a
Compare
A handler can now serve multiple URIs by holding a list of matchers instead of a single one: - setUri() replaces the list with one matcher (backward-compatible) - addUri() appends an additional URI matcher - clearUris() removes all matchers One HTTP method mask (setMethod) applies to all URIs of a handler. Use separate handlers when different URIs need different methods (e.g. a GET handler and a POST handler with onBody/onUpload callbacks). Applies to both AsyncCallbackWebHandler and AsyncCallbackJsonWebHandler. - New MultiRoute example: one handler serving multiple URIs in static RAM, PSRAM handler on multiple URIs, separate handlers per method - Updated docs: routing.md (Multiple URIs per Handler section), configuration.md, concepts.md Fully backward compatible: existing code using on(), addHandler(), serveStatic(), and single-URI handlers works identically. Motivation from #468 discussion. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
mathieucarbou
force-pushed
the
feat/routing_table_v2
branch
from
October 15, 2026 12:26
5af711a to
c440954
Compare
Member
Author
|
Superseded by #496 - branch renamed to feat/routing_table (removed _v2 suffix) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A handler can now serve multiple URIs and accept multiple HTTP methods by holding a list of matchers instead of a single one.
handler.setUri(matcher)handler.addUri(matcher)handler.clearUris()setMethod()accepts a composite mask — one method mask applies to all URIs of a handler:When different methods need different callbacks (e.g.
POSTwithonBody/onUpload), use separate handler objects.Applies to both
AsyncCallbackWebHandlerandAsyncCallbackJsonWebHandler.Motivation
In the #468 discussion, @inF1704 pointed out that URI matching lives inside handler objects (
AsyncCallbackWebHandlercarries_uriand_method), which prevents one handler from serving multiple routes.Instead of introducing a server-side routing table (
addRoute()), this PR moves URI matching to a list inside the handler. The handler declares what URIs it serves — no parallel routing data structure in the server, no split-brain matching logic.Usage
One Handler, Multiple URIs
Multiple URIs × Multiple Methods
Combine both — one handler, several URIs, accepting several HTTP methods:
Different Methods Need Different Callbacks → Different Handlers
When methods need different callbacks (e.g.
POSTwithonBody/onUpload), use separate handler objects:PSRAM Handler on Multiple URIs (ESP32)
Backward Compatibility
Fully backward compatible. Existing code using
server.on(),addHandler(),serveStatic(), and single-URI handlers (setUri()) works identically — no migration required.setUri()replaces the list with one matcher, so existing code that callssetUri()once behaves exactly as before.AsyncCallbackJsonWebHandler's constructor still takes a singleAsyncURIMatcherand internally callssetUri().Changes
src/WebHandlerImpl.hAsyncCallbackWebHandler::_uri→std::list<AsyncURIMatcher> _uris; newaddUri()/clearUris();setMethod()doc notes composite supportsrc/WebHandlers.cppsetUri()clears+pushes;canHandle()iterates_urissrc/AsyncJson.hAsyncCallbackJsonWebHandler::_uri→_uris; inlinesetUri()/addUri()/clearUris();setMethod()doc notes composite supportsrc/AsyncJson.cpp_uris;canHandle()iterates_urisexamples/arduino/MultiRoute/MultiRoute.inodocs/routing.mddocs/configuration.mddocs/concepts.mdplatformio.iniExample
See MultiRoute — one handler serving multiple URIs with
HTTP_GET | HTTP_POST, a PSRAM handler on multiple URIs, and a separate handler for POST withonBody.Documentation