| name | salvo-path-syntax |
| description | Path parameter syntax guide for Salvo routing. Explains the `{}` syntax (v0.76+) vs deprecated `<>` syntax, with migration examples. |
| version | 0.89.3 |
| tags | ["core","routing","path-syntax","migration"] |
Salvo Path Parameter Syntax
This skill explains the path parameter syntax changes in Salvo and provides migration guidance.
Syntax Version History
Version 0.76 and Later (Current)
Starting from Salvo 0.76, path parameters use curly braces {} syntax:
Router::with_path("users/{id}").get(get_user)
Router::with_path("users/{id:num}").get(get_user)
Router::with_path(r"users/{id|\d+}").get(get_user)
Router::with_path("files/{*}").get(handler)
Router::with_path("files/{*filename}").get(handler)
Router::with_path("static/{**path}").get(serve_static)
Before Version 0.76 (Deprecated)
In versions before 0.76, path parameters used angle brackets <> syntax:
Router::with_path("users/<id>").get(get_user)
Router::with_path("users/<id:num>").get(get_user)
Router::with_path(r"users/<id|\d+>").get(get_user)
Router::with_path("files/<*>").get(handler)
Router::with_path("files/<*filename>").get(handler)
Router::with_path("static/<**path>").get(serve_static)
Migration Guide
Quick Reference Table
| Pattern Type | Before 0.76 (Deprecated) | 0.76+ (Current) |
|---|
| Basic param | <id> | {id} |
| Typed param | <id:num> | {id:num} |
| Regex param | <id|\d+> | {id|\d+} |
| Single wildcard | <*> | {*} |
| Named wildcard | <*name> | {*name} |
| Rest wildcard | <**> | {**} |
| Named rest | <**path> | {**path} |
Migration Steps
- Find all route definitions using
<> syntax
- Replace angle brackets with curly braces
- Update tests if they reference path patterns
- Verify all routes work correctly
Example Migration
Before (deprecated):
let router = Router::new()
.push(
Router::with_path("api/v1")
.push(
Router::with_path("users")
.get(list_users)
.push(
Router::with_path("<id>")
.get(get_user)
.delete(delete_user)
)
)
.push(
Router::with_path("files/<**path>")
.get(serve_file)
)
);
After (current):
let router = Router::new()
.push(
Router::with_path("api/v1")
.push(
Router::with_path("users")
.get(list_users)
.push(
Router::with_path("{id}")
.get(get_user)
.delete(delete_user)
)
)
.push(
Router::with_path("files/{**path}")
.get(serve_file)
)
);
Parameter Types
Both syntaxes support the same type constraints (shown in current {} syntax):
Router::with_path("users/{id:num}")
Router::with_path("users/{id:i32}")
Router::with_path("users/{id:i64}")
Router::with_path("users/{id:u32}")
Router::with_path("users/{id:u64}")
Router::with_path(r"posts/{slug|[a-z0-9-]+}")
Router::with_path(r"users/{id|[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}}")
Accessing Parameters in Handlers
Parameter access is the same regardless of syntax version:
#[handler]
async fn get_user(req: &mut Request) -> String {
let id: i64 = req.param("id").unwrap();
let id = req.param::<i64>("id").unwrap();
format!("User ID: {}", id)
}
#[handler]
async fn serve_file(req: &mut Request) -> String {
let path: String = req.param("path").unwrap();
format!("Serving: {}", path)
}
Common Mistakes
Using Wrong Syntax for Version
Router::with_path("users/<id>")
Router::with_path("users/{id}")
Mixing Syntaxes
Router::with_path("users/{id}/posts/<post_id>")
Router::with_path("users/{id}/posts/{post_id}")
Version Detection
Check your Salvo version in Cargo.toml:
[dependencies]
salvo = "0.76"
salvo = "0.75"
For the latest version, always use {} syntax:
[dependencies]
salvo = "0.89.3"
Note: The {} syntax was introduced in version 0.76 and is used in all versions since then.
Best Practices
- Always use
{} syntax for new projects
- Migrate existing projects to
{} syntax when updating Salvo
- Use typed parameters when possible for automatic validation
- Use regex constraints for complex validation requirements
- Name your wildcards for clarity (
{**path} instead of {**})
Related Skills
- salvo-routing: Full routing configuration guide
- salvo-basic-app: Basic application setup