fork of https://github.com/c9s/r3 because they cant into cmake or dependency management
Go to file
2014-05-15 01:00:54 +08:00
cmake_modules Check in files. 2014-05-15 00:15:19 +08:00
src cmake: include_subdirectory(src) and include_subdirectory(tests) 2014-05-15 00:47:52 +08:00
tests Fix cmakelist file 2014-05-15 00:41:08 +08:00
.gitignore Fix cmakelist file 2014-05-15 00:41:08 +08:00
CMakeLists.txt clean up cmakelist 2014-05-15 00:59:22 +08:00
demo.c cmake: include_subdirectory(src) and include_subdirectory(tests) 2014-05-15 00:47:52 +08:00
HACKING.md update reading list 2014-05-15 01:00:54 +08:00
main.c Check in files. 2014-05-15 00:15:19 +08:00
main.h Check in files. 2014-05-15 00:15:19 +08:00
README.md Rename to R3 2014-05-15 00:18:59 +08:00

R3

R3 is an URI router library. It compiles your route paths into a radix tree. By using the constructed radix tree in the start-up time, you may dispatch your routes efficiently.

Pattern Syntax

/blog/post/{id}      use [^/]+ regular expression by default.

/blog/post/{id:\d+}  use `\d+` regular expression instead of default.

Use case in PHP

// Here is the paths data structure
$paths = [
    '/blog/post/{id}' => [ 'controller' => 'PostController' , 'action' => 'item'   , 'method'   => 'GET' ] , 
    '/blog/post'      => [ 'controller' => 'PostController' , 'action' => 'list'   , 'method'   => 'GET' ] , 
    '/blog/post'      => [ 'controller' => 'PostController' , 'action' => 'create' , 'method' => 'POST' ]  , 
    '/blog'           => [ 'controller' => 'BlogController' , 'action' => 'list'   , 'method'   => 'GET' ] , 
];
$rs = r2_compile_radix($paths, 'persisten-table-id');
$ret = r2_dispatch_radix($rs, '/blog/post/3' );
list($complete, $route, $variables) = $ret;

list($error, $message) = r2_validate($route); // validate route conditions
if ( $error ) {
    echo $message; // "Method not allowed", "...";
}