一键导入
salvo-path-syntax
Path parameter syntax guide for Salvo routing. Explains the `{}` syntax (v0.76+) vs deprecated `<>` syntax, with migration examples.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Path parameter syntax guide for Salvo routing. Explains the `{}` syntax (v0.76+) vs deprecated `<>` syntax, with migration examples.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Implement authentication and authorization using JWT, Basic Auth, or custom schemes. Use for securing API endpoints and user management.
Create basic Salvo web applications with handlers, routers, and server setup. Use when starting a new Salvo project or adding basic HTTP endpoints.
Implement caching strategies for improved performance. Use for reducing database load and speeding up responses.
Compress HTTP responses using gzip, brotli, zstd, or deflate. Use for reducing bandwidth and improving load times.
Limit concurrent requests to protect resources. Use for file uploads, expensive operations, and preventing resource exhaustion.
Configure Cross-Origin Resource Sharing (CORS) and security headers. Use for APIs accessed from browsers on different domains.
| 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.94.0 |
| tags | ["core","routing","path-syntax","migration"] |
Salvo 0.76+ uses curly-brace syntax {...} for path parameters. The old angle-bracket form <...> (pre-0.76) is removed and will not match.
Router::with_path("users/{id}") // basic
Router::with_path("users/{id:num}") // typed (num|i32|i64|u32|u64)
Router::with_path(r"users/{id|\d+}") // regex
Router::with_path("files/{*}") // single-segment wildcard
Router::with_path("files/{*name}") // named single-segment wildcard
Router::with_path("static/{**path}") // rest-of-path wildcard
| Before 0.76 | 0.76+ |
|---|---|
<id> | {id} |
<id:num> | {id:num} |
<id|\d+> | {id|\d+} |
<*> / <*name> | {*} / {*name} |
<**> / <**path> | {**} / {**path} |
Mechanical substitution: < to {, > to } in every with_path(...) / path(...) argument. Update any tests asserting on path strings.
BAD (pre-0.76, will not match in current Salvo):
Router::with_path("users/<id>/posts/<**rest>")
GOOD:
Router::with_path("users/{id}/posts/{**rest}")
Router::with_path("users/{id:num}") // any integer
Router::with_path("users/{id:i32}") // signed 32-bit
Router::with_path("users/{id:i64}")
Router::with_path("users/{id:u32}")
Router::with_path("users/{id:u64}")
// Regex: characters between `|` and `}` form the pattern
Router::with_path(r"posts/{slug|[a-z0-9-]+}")
Router::with_path(r"users/{id|[0-9a-f-]{36}}") // UUID
Typed and regex parameters reject non-matching values at the routing layer (returns 404), so handlers can unwrap.
#[handler]
async fn show(req: &mut Request) -> String {
let id: i64 = req.param("id").unwrap();
format!("id = {id}")
}
#[handler]
async fn serve(req: &mut Request) -> String {
let rest: String = req.param("path").unwrap(); // from {**path}
format!("serving {rest}")
}
req.param::<T>(name) returns Option<T> and deserializes via serde.
"users/{id}/posts/<pid>" will not compile-error but the <pid> segment is treated as a literal.{**} are greedy and capture trailing slashes — name them for clarity: {**path}.{*} matches exactly one segment; {**} matches zero or more. Use {*name} when you need a single non-empty segment.