From 684eac876cc77ad99059f3e83a1d1a08060039e0 Mon Sep 17 00:00:00 2001 From: c9s Date: Sun, 18 May 2014 14:11:53 +0800 Subject: [PATCH] readme update: routeing with conditions --- README.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/README.md b/README.md index 3e2e01e..115d8ef 100644 --- a/README.md +++ b/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 ); ``` +### 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