pub struct Mise { /* private fields */ }Expand description
Server resource and entry point.
Example:
use mise_server::prelude::*;
use serde_json::json;
Mise::new()
.get("/found", |_| json!("hello world").into())
.get("/not", |_| StatusCode::NOT_FOUND.into())
.get("/param", |r| json!(r.query_param("a").unwrap()).into())
.get("/error", |_| panic!("error"))
.text("/text", || "result".to_string())
.post("/echo", |r| r.body().clone().into())
.get("/get_echo/*", |r| json!(r.name()).into())
.serve("127.0.0.1:8080".parse().unwrap());Implementations§
Source§impl Mise
impl Mise
Sourcepub fn text<F: TextRoute>(self, path: &str, f: F) -> Self
pub fn text<F: TextRoute>(self, path: &str, f: F) -> Self
Register a text result only. This is used for cases such as prometheus scrape renders. Text routes always take precedence even if the route is already defined for any other methods.
Sourcepub fn post<F: Route>(self, path: &str, f: F) -> Self
pub fn post<F: Route>(self, path: &str, f: F) -> Self
Registers a post route. Body is obtained from Request::body and it is always a json Value.
Sourcepub fn serve(self, addr: SocketAddr)
pub fn serve(self, addr: SocketAddr)
Starts the server. Blocks until the server quits. Can panic if cannot bind the server.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Mise
impl !RefUnwindSafe for Mise
impl !Send for Mise
impl !Sync for Mise
impl Unpin for Mise
impl !UnwindSafe for Mise
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