Skip to content

Latest commit

 

History

History
33 lines (29 loc) · 1.06 KB

ROUTE_RESOLUTION.md

File metadata and controls

33 lines (29 loc) · 1.06 KB

Route Resolution Algorithm

The route resolution algorithm should be fairly clear. It goes like this:

Construction

  1. Remove query params, attach to the request object (or somewhere accessible for later)
  2. Break a route down by slashes, you now have a list of components
  3. Add into a tree, treating * and :param as wild cards ex. get("/a/b") and get(":id") should make a tree like this
root (/)
|\
| \
a  *
|
|
b

Resolution

  1. Split the incoming route in the same way as during construction
  2. Set current_node = root
  3. If split.get(0) does not exist, you're done, return the accumulated middleware
  4. Check if the first piece (split.get(0)) matches current_node
    1. If it does
      1. Set current_node = child
      2. Accumulate any middleware attached to that node.
    2. If it does not
      1. Check if there is a wildcard node, if so then current_node = current_node.wildcard
      2. If no wildcard, then the route isn't found, call the 404 handler.
  5. Remove the first piece of the split (or increment index)
  6. Go back to 3