Context

Struct Context 

Source
pub struct Context {
    pub method: String,
    pub path: String,
    pub params: HashMap<String, String>,
    pub headers: HashMap<String, String>,
    pub query: HashMap<String, String>,
    pub body: Value,
    pub user_id: Option<String>,
    pub is_admin: bool,
    pub request_id: Option<String>,
}
Expand description

Context passed to plugin handlers.

Contains all information about the incoming request.

Fields§

§method: String

HTTP method (GET, POST, etc.)

§path: String

Request path

§params: HashMap<String, String>

Path parameters (extracted from route pattern)

§headers: HashMap<String, String>

Request headers

§query: HashMap<String, String>

Query string parameters

§body: Value

Request body (parsed as JSON)

§user_id: Option<String>

Authenticated user ID (if any)

§is_admin: bool

Whether the user is an admin

§request_id: Option<String>

Request ID for tracing

Implementations§

Source§

impl Context

Source

pub fn from_raw(_ptr: i32, _len: i32) -> Result<Self>

Parse context from raw FFI pointer (non-WASM stub)

Source

pub fn param(&self, name: &str) -> Option<&str>

Get a path parameter by name

Source

pub fn param_required(&self, name: &str) -> Result<&str>

Get a required path parameter, or return an error

Source

pub fn query_param(&self, name: &str) -> Option<&str>

Get a query parameter by name

Source

pub fn query_param_or<'a>(&'a self, name: &str, default: &'a str) -> &'a str

Get a query parameter with a default value

Source

pub fn query_param_as<T: FromStr>(&self, name: &str) -> Option<T>

Get a query parameter parsed as a specific type

Source

pub fn header(&self, name: &str) -> Option<&str>

Get a header by name (case-insensitive)

Source

pub fn body_as<T: for<'de> Deserialize<'de>>(&self) -> Result<T>

Parse the request body as a specific type

Source

pub fn body_field(&self, name: &str) -> Option<&Value>

Get a field from the body

Source

pub fn body_field_as<T: for<'de> Deserialize<'de>>( &self, name: &str, ) -> Result<Option<T>>

Get a field from the body as a specific type

Source

pub const fn is_authenticated(&self) -> bool

Check if the request is authenticated

Source

pub fn require_auth(&self) -> Result<&str>

Require authentication, return error if not authenticated

Source

pub fn require_admin(&self) -> Result<()>

Require admin access

Source

pub fn is_method(&self, method: &str) -> bool

Check if the request method matches

Source

pub fn pagination(&self) -> (u32, u32)

Get pagination parameters from query string

Returns (page, per_page) with defaults of (1, 20)

Source

pub fn pagination_offset(&self) -> (u32, u32)

Get offset/limit for database queries from pagination

Returns (offset, limit)

Trait Implementations§

Source§

impl Clone for Context

Source§

fn clone(&self) -> Context

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Context

Source§

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

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

impl<'de> Deserialize<'de> for Context

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Context

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,