Skip to content

Commit dbc771d

Browse files
author
Eric O'Connor
committed
Explain "tree routing" in the README
1 parent b5c8fa4 commit dbc771d

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

README.md

+27
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,33 @@
66

77
Tree-Router is a library that handles routing, error handling, and authentication "gates" for your Node.js web application.
88

9+
The "tree" part is that instead of defining your routes using regular expressions and string matching, tree-router defines a formal tree (a series of hierarchical nodes with children), and then handles routing based on simple rules defined on the tree. This makes reasoning about application routing much easier.
10+
11+
For example, the routes:
12+
13+
```
14+
[orange, banana, apple]
15+
[orange, kiwi, strawberry]
16+
[orange, kiwi, strawberry, mango]
17+
[blackberry, raspberry]
18+
```
19+
20+
defines a tree that looks like
21+
22+
```
23+
__ROOT__
24+
/ \
25+
orange blackberry
26+
/ \ \
27+
kiwi banana raspberry
28+
| \
29+
strawberry apple
30+
|
31+
mango
32+
```
33+
34+
Any partial matches are routed to the closest match, which can either handle the ```request.unused``` path elements, or throw an error. Errors are bubbled up the tree to the nearest error handler in the hierarchy. Authentication and authorization "gates" are triggered while traversing down, allowing application authors to reason about exactly what URL paths are allowed.
35+
936
It assumes that node is being run with --harmony, to get Map and WeakMap support.
1037

1138
## Usage

0 commit comments

Comments
 (0)