Body

Struct Body 

Source
pub struct Body { /* private fields */ }

Implementations§

Source§

impl Body

Source

pub fn new() -> Body

Source

pub fn from_string(s: &str) -> Body

Source

pub fn from_bytes(b: Vec<u8>) -> Body

Source

pub fn as_string(&self) -> String

Source

pub fn as_bytes(&self) -> &[u8]

Source

pub fn json<T>(&self) -> Option<T>

Examples found in repository?
examples/routing.rs (line 34)
18fn main() {
19    let mut app = Server::new();
20
21    // Basic GET route
22    app.get("/", |_req| async {
23        Response::text("Welcome to Axeon API server!")
24    });
25
26    // Route with path parameter
27    app.get("/users/:id", |req| async move {
28        let user_id = req.params.get("id").unwrap();
29        Response::text(format!("User ID: {}", user_id))
30    });
31
32    // POST request with JSON body
33    app.post("/users", |req| async move {
34        match req.body.json::<User>() {
35            Some(user) => Response::ok(&user),
36            None => Err(ServerError::BadRequest("Invalid JSON body".to_string())),
37        }
38    });
39
40    // Group routes under /api prefix
41    let mut api = Router::new();
42    api.get("/status", |_req| async {
43        Response::ok(&serde_json::json!({
44            "status": "operational",
45            "version": "1.0.0"
46        }))
47    });
48
49    // Mount the API router to the main server
50    app.mount("/api", api);
51
52    app.listen("127.0.0.1:3000")
53        .expect("Server failed to start")
54}
Source

pub fn x_www_form_urlencoded<T>(&self) -> Option<T>

Source

pub fn form_data<T>(&self) -> Option<T>

Trait Implementations§

Source§

impl Debug for Body

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Vec<u8>> for Body

Source§

fn from(b: Vec<u8>) -> Body

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for Body

§

impl RefUnwindSafe for Body

§

impl Send for Body

§

impl Sync for Body

§

impl Unpin for Body

§

impl UnwindSafe for Body

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.