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

feat!: add http method matching #59

Closed
wants to merge 18 commits into from

Conversation

Hebilicious
Copy link
Member

@Hebilicious Hebilicious commented Jul 29, 2023

πŸ”— 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)
  • ✨ 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 #59 (comment).

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@codecov
Copy link

codecov bot commented Jul 29, 2023

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%> (ΓΈ)

@Hebilicious Hebilicious marked this pull request as draft July 29, 2023 14:59
src/router.ts Outdated Show resolved Hide resolved
src/router.ts Outdated Show resolved Hide resolved
src/router.ts Outdated Show resolved Hide resolved
tests/router.test.ts Outdated Show resolved Hide resolved
tests/router.test.ts Outdated Show resolved Hide resolved
@Hebilicious Hebilicious force-pushed the feat/add-http-method-matching branch from 0b7074e to 8b8474d Compare July 30, 2023 06:35
@Hebilicious Hebilicious marked this pull request as ready for review July 30, 2023 09:13
@Hebilicious
Copy link
Member Author

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

@Hebilicious Hebilicious changed the title feat: add http method matching feat!: add http method matching Sep 2, 2023
@Hebilicious
Copy link
Member Author

Hebilicious commented Sep 2, 2023

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

@pi0 pi0 added the pending label Sep 8, 2023
@pi0
Copy link
Member

pi0 commented Sep 8, 2023

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

@pi0
Copy link
Member

pi0 commented Jul 4, 2024

Implemented in #107

@pi0 pi0 closed this Jul 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Native support for http method matching
2 participants