readme update: routeing with conditions
This commit is contained in:
parent
bcd514989c
commit
684eac876c
1 changed files with 27 additions and 0 deletions
27
README.md
27
README.md
|
@ -55,6 +55,33 @@ matched_node->endpoint; // make sure there is a route end at here.
|
||||||
int ret = *( (*int) matched_node->route_ptr );
|
int ret = *( (*int) matched_node->route_ptr );
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Routing with conditions
|
||||||
|
|
||||||
|
```c
|
||||||
|
// create a router tree with 10 children capacity (this capacity can grow dynamically)
|
||||||
|
n = r3_tree_create(10);
|
||||||
|
|
||||||
|
int route_data = 3;
|
||||||
|
|
||||||
|
match_entry * entry = match_entry_create("/foo/bar");
|
||||||
|
|
||||||
|
// insert the route path into the router tree
|
||||||
|
route *r1 = route_create("/blog/post");
|
||||||
|
r1->request_method = METHOD_GET | METHOD_POST; // ALLOW GET OR POST
|
||||||
|
|
||||||
|
r3_tree_insert_route(n, r1, NULL, &route_data );
|
||||||
|
|
||||||
|
r3_tree_compile(n);
|
||||||
|
|
||||||
|
node *matched_node = r3_tree_match(n, "/foo/bar", strlen("/foo/bar"), entry);
|
||||||
|
matched_node->endpoint; // make sure there is a route end at here.
|
||||||
|
|
||||||
|
if (matched_node->routes) {
|
||||||
|
route *c = r3_node_match_route(m, entry);
|
||||||
|
c->data; // get the data from matched route
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Benchmark
|
Benchmark
|
||||||
|
|
Loading…
Reference in a new issue