pub struct RouteInfo {
pub method: String,
pub pattern: String,
}Expand description
A path-based HTTP router with named parameter extraction.
Register routes with Router::get, Router::post, etc. Each handler
receives the parsed PathParams alongside the raw Request and
ConnectionInfo. Call Router::handle from inside a [Controller]
or an [Application::execute] implementation.
§Example
use rust_web_server::router::{Router, PathParams};
use rust_web_server::request::Request;
use rust_web_server::response::{Response, STATUS_CODE_REASON_PHRASE};
use rust_web_server::range::Range;
use rust_web_server::mime_type::MimeType;
use rust_web_server::server::ConnectionInfo;
use rust_web_server::core::New;
let router = Router::new()
.get("/hello", |_req, _params, _conn| {
let mut r = Response::new();
r.status_code = *STATUS_CODE_REASON_PHRASE.n200_ok.status_code;
r.reason_phrase = STATUS_CODE_REASON_PHRASE.n200_ok.reason_phrase.to_string();
r.content_range_list = vec![Range::get_content_range(b"hello".to_vec(), MimeType::TEXT_PLAIN.to_string())];
r
})
.get("/users/:id", |_req, params, _conn| {
let id = params.get("id").unwrap_or("unknown");
let mut r = Response::new();
r.status_code = *STATUS_CODE_REASON_PHRASE.n200_ok.status_code;
r.reason_phrase = STATUS_CODE_REASON_PHRASE.n200_ok.reason_phrase.to_string();
r.content_range_list = vec![Range::get_content_range(
format!("user {}", id).into_bytes(),
MimeType::TEXT_PLAIN.to_string(),
)];
r
});A registered route entry returned by Router::route_entries.
Fields§
§method: String§pattern: StringTrait Implementations§
Auto Trait Implementations§
impl Freeze for RouteInfo
impl RefUnwindSafe for RouteInfo
impl Send for RouteInfo
impl Sync for RouteInfo
impl Unpin for RouteInfo
impl UnsafeUnpin for RouteInfo
impl UnwindSafe for RouteInfo
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more