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
@@ -8,6 +8,15 @@ The `AsyncURIMatcher` class provides flexible and powerful URL routing mechanism
8
8
9
9
**Important**: When using plain strings (not `AsyncURIMatcher` objects), the library uses auto-detection (`URIMatchAuto`) which analyzes the URI pattern and applies appropriate matching rules. This is **not** simple exact matching - it combines exact and folder matching by default!
10
10
11
+
## What's Demonstrated
12
+
13
+
This example includes two Arduino sketches:
14
+
15
+
1.**URIMatcher.ino** - Interactive web-based demonstration with a user-friendly homepage
16
+
2.**URIMatcherTest.ino** - Comprehensive test suite with automated shell script testing
17
+
18
+
Both sketches create a WiFi Access Point (`esp-captive`) for easy testing without network configuration.
19
+
11
20
## Auto-Detection Behavior
12
21
13
22
When you pass a plain string or `const char*` to `server.on()`, the `URIMatchAuto` flag is used, which:
@@ -19,72 +28,159 @@ When you pass a plain string or `const char*` to `server.on()`, the `URIMatchAut
19
28
5.**Everything else**: Becomes **both** exact and folder match (`URIMatchPrefixFolder | URIMatchExact`)
20
29
21
30
This means traditional string-based routes like `server.on("/path", handler)` will match:
31
+
22
32
-`/path` (exact match)
33
+
-`/path/` (folder with trailing slash)
23
34
-`/path/anything` (folder match)
24
35
25
36
But will **NOT** match `/path-suffix` (prefix without folder separator).
26
37
27
38
## Features Demonstrated
28
39
29
40
### 1. **Auto-Detection (Traditional Behavior)**
30
-
- When using plain strings, automatically detects the appropriate matching strategy
31
-
- Default behavior: combines exact and folder matching
- Use cases: Traditional ESP32 web server behavior with enhanced capabilities
34
-
- Examples: `/path` matches both `/path` and `/path/sub`
35
41
36
-
### 2. **Exact Matching**
37
-
- Matches only the exact URL specified
38
-
- Use cases: API endpoints, specific pages
39
-
- Examples: `/exact`, `/login`, `/dashboard`
42
+
Demonstrates how traditional string-based routing automatically combines exact and folder matching.
43
+
44
+
**Examples in URIMatcher.ino:**
45
+
46
+
-`/auto` - Matches both `/auto` exactly AND `/auto/sub` as folder
47
+
-`/wildcard*` - Auto-detects as prefix match (due to trailing `*`)
48
+
-`/auto-images/*.png` - Auto-detects as extension match (due to `/*.ext` pattern)
49
+
50
+
**Examples in URIMatcherTest.ino:**
51
+
52
+
-`/exact` - Matches `/exact`, `/exact/`, and `/exact/sub`
53
+
-`/api/users` - Matches exact path and subpaths under `/api/users/`
54
+
-`/*.json` - Matches any `.json` file anywhere
55
+
-`/*.css` - Matches any `.css` file anywhere
56
+
57
+
### 2. **Exact Matching (Factory Method)**
58
+
59
+
Using `AsyncURIMatcher::exact()` matches only the exact URL, **NOT** subpaths.
60
+
61
+
**Key difference from auto-detection:**`AsyncURIMatcher::exact("/path")` matches **only**`/path`, while `server.on("/path", ...)` matches both `/path` and `/path/sub`.
62
+
63
+
**Examples in URIMatcher.ino:**
64
+
65
+
-`AsyncURIMatcher::exact("/exact")` - Matches only `/exact`
66
+
67
+
**Examples in URIMatcherTest.ino:**
68
+
69
+
-`AsyncURIMatcher::exact("/factory/exact")` - Matches only `/factory/exact`
70
+
- Does NOT match `/factory/exact/sub` (404 response)
40
71
41
72
### 3. **Prefix Matching**
42
-
- Matches URLs that start with the specified pattern
43
-
- Use cases: API versioning, module grouping
44
-
- Examples: `/api*` matches `/api/users`, `/api/posts`, etc.
73
+
74
+
Using `AsyncURIMatcher::prefix()` matches URLs that start with the specified pattern.
0 commit comments