Struct axum_extra::routing::Resource [−][src]
pub struct Resource<B = Body> { /* fields omitted */ }
Expand description
A resource which defines a set of conventional CRUD routes.
Example
use axum::{Router, routing::get, extract::Path};
use axum_extra::routing::{RouterExt, Resource};
let users = Resource::named("users")
// Define a route for `GET /users`
.index(|| async {})
// `POST /users`
.create(|| async {})
// `GET /users/new`
.new(|| async {})
// `GET /users/:users_id`
.show(|Path(user_id): Path<u64>| async {})
// `GET /users/:users_id/edit`
.edit(|Path(user_id): Path<u64>| async {})
// `PUT or PATCH /users/:users_id`
.update(|Path(user_id): Path<u64>| async {})
// `DELETE /users/:users_id`
.destroy(|Path(user_id): Path<u64>| async {})
// Nest another router at the "member level"
// This defines a route for `GET /users/:users_id/tweets`
.nest(Router::new().route(
"/tweets",
get(|Path(user_id): Path<u64>| async {}),
))
// Nest another router at the "collection level"
// This defines a route for `GET /users/featured`
.nest_collection(
Router::new().route("/featured", get(|| async {})),
);
let app = Router::new().with(users);
Implementations
Create a Resource
with the given name.
All routes will be nested at /{resource_name}
.
Add a handler at GET /{resource_name}
.
Add a handler at POST /{resource_name}
.
Add a handler at GET /{resource_name}/new
.
Add a handler at GET /{resource_name}/:{resource_name}_id
.
Add a handler at GET /{resource_name}/:{resource_name}_id/edit
.
Add a handler at PUT or PATCH /resource_name/:{resource_name}_id
.
Add a handler at DELETE /{resource_name}/:{resource_name}_id
.
Nest another route at the “member level”.
The routes will be nested at /{resource_name}/:{resource_name}_id
.
pub fn nest_collection<T>(self, svc: T) -> Self where
T: Service<Request<B>, Response = Response, Error = Infallible> + Clone + Send + 'static,
T::Future: Send + 'static,
pub fn nest_collection<T>(self, svc: T) -> Self where
T: Service<Request<B>, Response = Response, Error = Infallible> + Clone + Send + 'static,
T::Future: Send + 'static,
Nest another route at the “collection level”.
The routes will be nested at /{resource_name}
.
Trait Implementations
Auto Trait Implementations
impl<B = Body> !RefUnwindSafe for Resource<B>
impl<B = Body> !UnwindSafe for Resource<B>
Blanket Implementations
Mutably borrows from an owned value. Read more
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more