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

Guide - Routes #14

Open
crisward opened this issue Sep 29, 2017 · 2 comments
Open

Guide - Routes #14

crisward opened this issue Sep 29, 2017 · 2 comments

Comments

@crisward
Copy link
Contributor

There is a line in the guide which says

Routes are matched in the order they are defined. The first route that matches the request is invoked.

I'm not sure this is correct. Radix won't allow two identical routes, and those with overlap, the more specific tends to win... I think? Perhaps @luislavena can confirm.

@sdogruyol
Copy link
Member

Yeah, It doesn't allow two identical routes. We need to document it in a more explicit way

@luislavena
Copy link

luislavena commented Oct 5, 2017

Hello, apologies for late reply...

Radix won't allow two identical routes, and those with overlap, the more specific tends to win... I think?

That's actually not accurate. Radix will not allow two equal routes but will allow adding a payload to a shorter one, example:

require "radix"

tree = Radix::Tree(Symbol).new

# this works
tree.add "/foo/bar/baz", :baz
tree.add "/foo/bar", :bar

# not found (no payload at `/foo`)
result = tree.find "/foo"
pp result.found? # => false

result = tree.find "/foo/bar/baz"
pp result.found?  # => true
pp result.payload # => :baz

result = tree.find "/foo/bar"
pp result.found?  # => true
pp result.payload # => :bar

Attempt to add any payload with the same path will result in Radix::Tree::DuplicateError exception.

Hope that helps.

Cheers.

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

No branches or pull requests

3 participants