pub trait Plugin: Send + Sync {
Show 13 methods
// Required method
fn name(&self) -> &str;
// Provided methods
fn on_init(&self, _ctx: &PluginContext) { ... }
fn routes(&self) -> Vec<PluginRoute> { ... }
fn before_insert(
&self,
_entity: &str,
_data: &mut Value,
_auth: &AuthContext,
) -> Result<(), PluginError> { ... }
fn after_insert(
&self,
_entity: &str,
_id: &str,
_data: &Value,
_auth: &AuthContext,
) { ... }
fn before_update(
&self,
_entity: &str,
_id: &str,
_data: &mut Value,
_auth: &AuthContext,
) -> Result<(), PluginError> { ... }
fn after_update(
&self,
_entity: &str,
_id: &str,
_data: &Value,
_auth: &AuthContext,
) { ... }
fn before_delete(
&self,
_entity: &str,
_id: &str,
_auth: &AuthContext,
) -> Result<(), PluginError> { ... }
fn after_delete(&self, _entity: &str, _id: &str, _auth: &AuthContext) { ... }
fn on_request(
&self,
_method: &str,
_path: &str,
_auth: &AuthContext,
) -> Result<(), PluginError> { ... }
fn on_request_with_meta(
&self,
method: &str,
path: &str,
auth: &AuthContext,
_meta: &RequestMeta<'_>,
) -> Result<(), PluginError> { ... }
fn on_session_create(&self, _user_id: &str, _token: &str) { ... }
fn entities(&self) -> Vec<ManifestEntity> { ... }
}Expand description
A plugin extends pylon with custom routes, lifecycle hooks, and entities.
Required Methods§
Provided Methods§
Sourcefn on_init(&self, _ctx: &PluginContext)
fn on_init(&self, _ctx: &PluginContext)
Called once when the plugin is registered.
Sourcefn routes(&self) -> Vec<PluginRoute>
fn routes(&self) -> Vec<PluginRoute>
Custom API routes this plugin handles.
Sourcefn before_insert(
&self,
_entity: &str,
_data: &mut Value,
_auth: &AuthContext,
) -> Result<(), PluginError>
fn before_insert( &self, _entity: &str, _data: &mut Value, _auth: &AuthContext, ) -> Result<(), PluginError>
Called before an entity insert. Return Err to reject.
Sourcefn after_insert(
&self,
_entity: &str,
_id: &str,
_data: &Value,
_auth: &AuthContext,
)
fn after_insert( &self, _entity: &str, _id: &str, _data: &Value, _auth: &AuthContext, )
Called after a successful insert.
Sourcefn before_update(
&self,
_entity: &str,
_id: &str,
_data: &mut Value,
_auth: &AuthContext,
) -> Result<(), PluginError>
fn before_update( &self, _entity: &str, _id: &str, _data: &mut Value, _auth: &AuthContext, ) -> Result<(), PluginError>
Called before an entity update. Return Err to reject.
Sourcefn after_update(
&self,
_entity: &str,
_id: &str,
_data: &Value,
_auth: &AuthContext,
)
fn after_update( &self, _entity: &str, _id: &str, _data: &Value, _auth: &AuthContext, )
Called after a successful update.
Sourcefn before_delete(
&self,
_entity: &str,
_id: &str,
_auth: &AuthContext,
) -> Result<(), PluginError>
fn before_delete( &self, _entity: &str, _id: &str, _auth: &AuthContext, ) -> Result<(), PluginError>
Called before an entity delete. Return Err to reject.
Sourcefn after_delete(&self, _entity: &str, _id: &str, _auth: &AuthContext)
fn after_delete(&self, _entity: &str, _id: &str, _auth: &AuthContext)
Called after a successful delete.
Sourcefn on_request(
&self,
_method: &str,
_path: &str,
_auth: &AuthContext,
) -> Result<(), PluginError>
fn on_request( &self, _method: &str, _path: &str, _auth: &AuthContext, ) -> Result<(), PluginError>
Called on every incoming request (middleware).
Sourcefn on_request_with_meta(
&self,
method: &str,
path: &str,
auth: &AuthContext,
_meta: &RequestMeta<'_>,
) -> Result<(), PluginError>
fn on_request_with_meta( &self, method: &str, path: &str, auth: &AuthContext, _meta: &RequestMeta<'_>, ) -> Result<(), PluginError>
Richer variant of [on_request] that also receives per-request
metadata (peer IP today; more fields may be added later). The
default implementation delegates to on_request so existing
plugins keep working without changes. Plugins that care about
IP — notably rate limiting — override this hook.
Sourcefn on_session_create(&self, _user_id: &str, _token: &str)
fn on_session_create(&self, _user_id: &str, _token: &str)
Called when a new session is created.
Sourcefn entities(&self) -> Vec<ManifestEntity>
fn entities(&self) -> Vec<ManifestEntity>
Additional manifest entities this plugin contributes.