12 releases

0.4.1 Apr 7, 2024
0.4.0 Mar 22, 2024
0.3.6 Jan 2, 2024
0.3.5 Mar 20, 2023
0.2.0 Jul 8, 2021

#1183 in HTTP server

Download history 725/week @ 2024-07-22 641/week @ 2024-07-29 624/week @ 2024-08-05 466/week @ 2024-08-12 420/week @ 2024-08-19 426/week @ 2024-08-26 461/week @ 2024-09-02 770/week @ 2024-09-09 276/week @ 2024-09-16 283/week @ 2024-09-23 471/week @ 2024-09-30 92/week @ 2024-10-07 248/week @ 2024-10-14 334/week @ 2024-10-21 542/week @ 2024-10-28 400/week @ 2024-11-04

1,527 downloads per month
Used in 9 crates (8 directly)

MIT/Apache

88KB
1.5K SLoC

Welcome to Trillium!

📖 Guide 📖

The guide provides an architectural overview and lay of the land connecting the trillium crates.

📑 Rustdocs 📑

The rustdocs represent the best way to learn about any of trillium's individual crates and the specific interfaces.




Legal:

Licensed under either of

at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


lib.rs:

Welcome to the trillium router crate!

This router is built on top of routefinder, and the details of route resolution and definition are documented on that repository.

use trillium::{conn_unwrap, Conn};
use trillium_router::{Router, RouterConnExt};

let router = Router::new()
.get("/", |conn: Conn| async move { conn.ok("you have reached the index") })
.get("/pages/:page_name", |conn: Conn| async move {
let page_name = conn_unwrap!(conn.param("page_name"), conn);
let content = format!("you have reached the page named {}", page_name);
conn.ok(content)
});

use trillium_testing::prelude::*;
assert_ok!(get("/").on(&router), "you have reached the index");
assert_ok!(get("/pages/trillium").on(&router), "you have reached the page named trillium");
assert_not_handled!(get("/unknown/route").on(&router));

Although this is currently the only trillium router, it is an important aspect of trillium's architecture that the router uses only public apis and is interoperable with other router implementations. If you have different ideas of how a router might work, please publish a crate! It should be possible to nest different types of routers (and different versions of router crates) within each other as long as they all depend on the same version of the trillium crate.

Options handling

By default, the trillium router will reply to an OPTIONS request with the list of supported http methods at the given route. If the OPTIONS request is sent for *, it responds with the full set of http methods supported by this router.

Note: This behavior is superceded by an explicit OPTIONS handler or an any handler.

To disable the default OPTIONS behavior, use Router::without_options_handling or RouterRef::set_options_handling

Dependencies

~7.5MB
~189K SLoC