feat!: add http method matching
π Linked issue
Resolves #58
β Type of change
- [ ] π Documentation (updates to the documentation, readme, or JSdoc annotations)
- [ ] π Bug fix (a non-breaking change that fixes an issue)
- [ ] π Enhancement (improving an existing functionality like performance)
- [x] β¨ New feature (a non-breaking change that adds functionality)
- [ ] π§Ή Chore (updates to the build process or auxiliary tools and libraries)
- [ ] β οΈ Breaking change (fix or feature that would cause existing functionality to change)
π Description
This PR adds a new syntax to allow http method to be matched with radix3.
const router = createRouter();
router.insert({ path: "v2", method: "GET", payload: { path: "v2" } }); //v2 syntax
router.insert("v1", { path: "v1", field: 1, anotherField: 2 }); //v1 syntax
The current implementation contains a (small) breaking to staticRoutesMap, which is now a 2 dimensional array to support fast method matching. A one dimensional approach is possible, but not as robust as the 2 dimensional one https://github.com/unjs/radix3/pull/59#discussion_r1278317571.
π Checklist
- [x] I have linked an issue or discussion.
- [ ] I have updated the documentation accordingly.
Codecov Report
Merging #59 (9c87773) into main (5ee7e67) will increase coverage by
0.74%. The diff coverage is100.00%.
@@ Coverage Diff @@
## main #59 +/- ##
==========================================
+ Coverage 95.41% 96.15% +0.74%
==========================================
Files 4 4
Lines 414 494 +80
Branches 79 94 +15
==========================================
+ Hits 395 475 +80
Misses 19 19
| Files Changed | Coverage Ξ | |
|---|---|---|
| src/router.ts | 100.00% <100.00%> (ΓΈ) |
|
| src/types.ts | 100.00% <100.00%> (ΓΈ) |
@pi0 Refactored according to your instructions, added benchmarks and more tests.
@pi0 Just revisiting this PR. I simplified it, rebased and added a description, as well as flagged it as a breaking change due to the staticRoutesMap change.
Put a pending label i need to still benchmark and validate it more.
Implemented in https://github.com/unjs/radix3/pull/107