radix3 icon indicating copy to clipboard operation
radix3 copied to clipboard

feat!: add http method matching

Open Hebilicious opened this issue 2 years ago β€’ 4 comments

πŸ”— 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.

Hebilicious avatar Jul 29 '23 14:07 Hebilicious

Codecov Report

Merging #59 (9c87773) into main (5ee7e67) will increase coverage by 0.74%. The diff coverage is 100.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%> (ΓΈ)

codecov[bot] avatar Jul 29 '23 14:07 codecov[bot]

@pi0 Refactored according to your instructions, added benchmarks and more tests.

Hebilicious avatar Jul 30 '23 09:07 Hebilicious

@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.

Hebilicious avatar Sep 02 '23 11:09 Hebilicious

Put a pending label i need to still benchmark and validate it more.

pi0 avatar Sep 08 '23 10:09 pi0

Implemented in https://github.com/unjs/radix3/pull/107

pi0 avatar Jul 04 '24 22:07 pi0