Expand description
Route-model binding — Laravel’s public function show(Post $post).
ⓘ
// routes/api.rs
router.get("/posts/{post}", show).where_slug("post");
// app/http/controllers/post_controller.rs
pub async fn show(Bound(post): Bound<Post>) -> Result<Response> {
Ok(Response::json(&post))
}The action receives the model, not the id: the lookup, the 404 and the
? are all gone from the body, and what is left is the thing the action is
actually about.
§Why it lives here
It needs a request, a container and a repository at once, and
rainier-database is not allowed to know an HTTP
request exists — that rule is what keeps a repository usable from a queue
worker with no router in it. This crate is the one that already has both
halves, the same reason
DatabaseChannel is here.
Structs§
Traits§
- Param
Key - The name of a route parameter, as a type. See
param_key!.