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

WHATWG URL Pattern: support for route matching #679

Open
meftunca opened this issue May 30, 2024 · 6 comments
Open

WHATWG URL Pattern: support for route matching #679

meftunca opened this issue May 30, 2024 · 6 comments

Comments

@meftunca
Copy link

What is the problem this feature will solve?

With this support we can increase the spread of ada-url. The library is really fast, but by adding a route matching feature for url, it can be a really inclusive library.

What is the feature you are proposing to solve the problem?

Here is my proposed solution:
/users/:id/friends with “:/” separated by the character “:/” to enable route matching. Of course, there may be more specific examples like
“{id}”,“[a-zAz]”

What alternatives have you considered?

Since this suggestion is usually found in router libraries, it is difficult to give a specific reference, but I have listed an example of its use below

  • :path-variable
  • {path-variable}
  • regex
@lemire
Copy link
Member

lemire commented May 30, 2024

Can you be more precise as to what you mean by 'route matching'. Do you refer to a specification?

@meftunca
Copy link
Author

@lemire ,I actually mean the user's route tokens, which is the main task of a router. as an example the following list may help

defined route incoming route by request
/api/v1/users/:userId /api/v1/users/35
/api/v1/products/:productId /api/v1/products/217

Of course, there may be specifications you want to stick to. But in general, I think it is very important to provide this structure that every http router basically needs. NodeJS uses your library if I'm not mistaken. Most routers under nodejs (expressjs, fastify ...) really waste time in the matching part. This feature can significantly improve the performance of such libraries

@lemire
Copy link
Member

lemire commented May 30, 2024

@meftunca My question stands: what is the specification you are are referencing? To be clearer, you propose that routing be implemented in ada, but a pre-requisite is that one has a formal definition of what routing means.

The one thing that comes to mind is the WHATWG URL Pattern specification. Is that what you mean, or do you mean something else?

@meftunca
Copy link
Author

meftunca commented May 30, 2024

Hello,

The feature I propose is to add URL routing, a common mechanism in web applications, to the ada-url library. This feature would allow incoming HTTP requests to be routed to the appropriate handler functions by matching their URLs against specific patterns.

This feature would expand the scope of ada-url, making it easier to develop more comprehensive web applications. For example, this feature would be very useful when building a REST API or serving different content to different URLs.

My proposed solution is to use placeholder values like /users/:id/friends in URL patterns. These placeholders would be matched with the actual values in the request's URL and passed as parameters to the handler function. Additionally, more flexible matching rules could be defined with dynamic segments like {id} or regex expressions like [a-zA-Z].

As ada-url already has the ability to parse URL parts, adding this feature could be relatively easy. This would allow application developers to perform URL routing using only the ada-url library.

This feature would make ada-url a more powerful and versatile tool, making life easier for many developers like me.
The routing feature I propose is based on the WHATWG URL Pattern specification. This standard defines a URL matching mechanism that is widely used in modern web applications and ensures consistency across different platforms. Adding this feature to the ada-url library would make ada-url a more powerful and versatile tool, making it easier for developers to build more complex web applications.
Reference link: https://urlpattern.spec.whatwg.org/#parsing
Thank you.

@lemire lemire changed the title Proposal for support for route matching WHATWG URL Pattern: support for route matching May 30, 2024
@lemire
Copy link
Member

lemire commented May 30, 2024

Ok. So we agree that the issue about WHATWG URL Pattern. I have retitled it.

@Ethan-Arrowood
Copy link

Hi folks, I started work on adding URL Pattern to Ada.

I'm new-ish to C++ and this is my first contribution to this repo, so it's taking me a little longer to figure out but chipping away slowly at it! I'll open a draft PR when its in a better state, but for now you can see the working branch: main...Ethan-Arrowood:ada:add-url_pattern

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants