pub struct RouteBuilder<S> { /* private fields */ }Expand description
Builder for configuring routes and settings before creating an App.
RouteBuilder uses a fluent API to register routes, configure CORS, and adjust
server settings. Call .seal() to produce the final App<S>.
§Example
ⓘ
use mini_serve::{RouteBuilder, handler, body};
use hyper::Response;
use hyper::body::Bytes;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let app = RouteBuilder::stateless()
.get("/health", handler(|_, _| async {
Ok(Response::new(body(Bytes::from("OK"))))
}))
.seal();
app.bind("127.0.0.1:8080".parse()?).await?;
Ok(())
}Implementations§
Source§impl<S: Send + Sync + 'static> RouteBuilder<S>
impl<S: Send + Sync + 'static> RouteBuilder<S>
Sourcepub fn with_max_body_size(self, max: usize) -> Self
pub fn with_max_body_size(self, max: usize) -> Self
Set the maximum request body size in bytes (default: 2 MiB).
Sourcepub fn with_header_read_timeout(self, d: Duration) -> Self
pub fn with_header_read_timeout(self, d: Duration) -> Self
Set the header read timeout (default: 30 seconds).
Sourcepub fn with_max_connections(self, max: usize) -> Self
pub fn with_max_connections(self, max: usize) -> Self
Set the maximum concurrent connections (default: 1024).
pub fn with_error_handler( self, f: impl Fn(StatusCode, &str) -> Response<ResponseBody> + Send + Sync + 'static, ) -> Self
pub fn with_cors(self, config: CorsConfig) -> Self
pub fn get(self, path: &str, handler: Handler<S>) -> Self
pub fn post(self, path: &str, handler: Handler<S>) -> Self
pub fn put(self, path: &str, handler: Handler<S>) -> Self
pub fn delete(self, path: &str, handler: Handler<S>) -> Self
pub fn seal(self) -> App<S>
Auto Trait Implementations§
impl<S> !RefUnwindSafe for RouteBuilder<S>
impl<S> !UnwindSafe for RouteBuilder<S>
impl<S> Freeze for RouteBuilder<S>
impl<S> Send for RouteBuilder<S>
impl<S> Sync for RouteBuilder<S>
impl<S> Unpin for RouteBuilder<S>
impl<S> UnsafeUnpin for RouteBuilder<S>
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