#http #router #darpi

gonzales

This crate provides routing objects for darpi

3 releases

0.0.3-beta May 22, 2021
0.0.2-beta May 15, 2021
0.0.1-beta May 14, 2021

#238 in Web programming

Download history 6/week @ 2021-10-01 7/week @ 2021-10-08 8/week @ 2021-10-15 75/week @ 2021-10-22 2/week @ 2021-10-29 30/week @ 2021-11-05 3/week @ 2021-11-12 6/week @ 2021-11-19 5/week @ 2021-11-26 9/week @ 2021-12-03 5/week @ 2021-12-10 2/week @ 2021-12-17 4/week @ 2021-12-24 6/week @ 2021-12-31 26/week @ 2022-01-07 33/week @ 2022-01-14

69 downloads per month
Used in 2 crates

MIT/Apache

43KB
1.5K SLoC

gonzales is the fastest http router in the business and has no unsafe code.

The benchmarks include 130 routes per iteration.

#Regular matching

test gonzales ... bench:                363 ns/iter (+/- 15)
test matchit ... bench:                 403 ns/iter (+/- 12)
test bench_regex_set ... bench:         39604 ns/iter (+/- 2274)
test bench_actix ... bench:             55248 ns/iter (+/- 2905)
test bench_route_recognizer ... bench:  13219 ns/iter (+/- 564)

#Case insensitive matching

test gonzales ... bench:         423 ns/iter (+/- 11)
test matchit ... bench:        3921 ns/iter (+/- 104)
test actix ... bench:       54038 ns/iter (+/- 1484)
test regex ... bench:       33513 ns/iter (+/- 3388)
test route-recognizer ... bench:       13622 ns/iter (+/- 1177)

It costs 1ns per character of input for matching. That leads to most routes being matched or not within 10ns to 20ns. It supports case insensitive matching without additional runtime costs. It also supports path arguments extraction.

Under the hood, it uses a DFA with a few extra perks. Many thanks to BurntSushi for his work in this field and his great articles such as this .

        let route = vec!["/hello/{user_id}", "/helloworld"];
        let router = RouterBuilder::new()
            .ascii_case_insensitive(true)
            .build(route);
        let m = router.route("/HelloWorld")?;

        // the index of the matched route
        let index = m.get_index();
        assert_eq!(1, index);
        
        // route arguments
        let args = m.get_args();
        assert!(args.is_empty());

        // segments matched with `*`
        let segments = m.get_segments();
        assert!(segments.is_empty());
        

The router also supports multi-segment matching with *, only at the end of a route. /hello/world/* will match every incoming request path that starts with /hello/world/.

arriba arriba andale andale!!!

Dependencies

~79KB

m\`