Radix-Router is a Rust port of julienschmidt/httprouter.
This is just a quick introduction.
Let's start with a
hello world example:
extern crate futures; extern crate hyper; extern crate pretty_env_logger; extern crate radix_router; use future; use ; use ; use ;
The handler can be a
closure. When using closure, you are able to capture outside parameters. For example:
router.get; router.post; router.post; router.post; router.get;
:name is a named parameter. The values are accessible via
Option<Params>, which is a wrapped slice of
Params. You can get the value of a parameter either by its index in the slice. of by using the
Named parameters only match a single path segment:
Pattern: /user/:user /user/gordon match /user/you match /user/gordon/profile no match /user/ no match
Note: Since this router has only explicit matches, you can not register static routes and parameters for the same path segment. For example you can not register the patterns
/user/:user for the same request method at the same time. The routing of different request methods is independent from each other.
The second type are catch-all parameters and have the form
*name. Like the name suggests, they match everything. Therefore they must always be at the end of the pattern:
Pattern: /src/*filepath /src/ match /src/somefile.go match /src/subdir/somefile.go match
You can serve static files by using:
An echo server example is written. You can test it by running