Module route_binding

Module route_binding 

Source
Expand description

Route model binding support

Provides automatic model resolution from route parameters.

§Automatic Route Model Binding

Route model binding is automatic for all SeaORM models whose Entity implements kit::database::Model. Simply use the Model type as a handler parameter:

use kit::{handler, json_response, Response};
use crate::models::user;

// Just use the Model in your handler - binding is automatic!
#[handler]
pub async fn show(user: user::Model) -> Response {
    json_response!({ "name": user.name })
}

The parameter name (user) is used as the route parameter key. So for a route defined as /users/{user}, the user parameter will be automatically resolved.

If the model is not found, a 404 Not Found response is returned. If the parameter cannot be parsed, a 400 Bad Request response is returned.

Traits§

AutoRouteBinding
Trait for automatic route model binding
RouteBinding
Trait for models that can be automatically resolved from route parameters