macro_rules! resource {
($path:expr, $($controller:ident)::+) => { ... };
($path:expr, $($controller:ident)::+, only: [$($action:ident),* $(,)?]) => { ... };
}Expand description
Define RESTful resource routes with convention-over-configuration
Generates 7 standard routes following Rails/Laravel conventions from a controller module reference.
§Convention Mapping
| Method | Path | Action | Route Name |
|---|---|---|---|
| GET | /users | index | users.index |
| GET | /users/create | create | users.create |
| POST | /users | store | users.store |
| GET | /users/{id} | show | users.show |
| GET | /users/{id}/edit | edit | users.edit |
| PUT | /users/{id} | update | users.update |
| DELETE | /users/{id} | destroy | users.destroy |
§Basic Usage
ⓘ
routes! {
resource!("/users", controllers::user),
}§With Middleware
ⓘ
routes! {
resource!("/admin", controllers::admin).middleware(AuthMiddleware),
}§Subset of Actions
Use only: to generate only specific routes:
ⓘ
routes! {
// Only index, show, and store - no create/edit forms, update, or destroy
resource!("/posts", controllers::post, only: [index, show, store]),
}§Path Naming
Route names are derived from the path:
/users→users.index,users.show, etc./api/users→api.users.index,api.users.show, etc.
§Compile Error
Fails to compile if path doesn’t start with ‘/’.