#[param]Expand description
Helper attribute for parameter-level HTTP customization.
This attribute is used on function parameters within #[http] impl blocks
to customize parameter extraction and naming. It is a no-op on its own.
Note: Requires nightly Rust with #![feature(register_tool)] and
#![register_tool(param)] at the crate root.
§Supported Options
name = "<wire_name>"- Use a different name on the wire (e.g.,qinstead ofquery)default = <value>- Provide a default value for optional parametersquery- Force parameter to come from query stringpath- Force parameter to come from URL pathbody- Force parameter to come from request bodyheader- Extract parameter from HTTP header
§Location Inference
When no location is specified, parameters are inferred based on conventions:
- Parameters named
idor ending in_id→ path parameters - POST/PUT/PATCH methods → body parameters
- GET/DELETE methods → query parameters
§Examples
ⓘ
#![feature(register_tool)]
#![register_tool(param)]
#[http(prefix = "/api")]
impl SearchService {
// Rename parameter: code uses `query`, API accepts `q`
fn search(&self, #[param(name = "q")] query: String) -> Vec<Result> {
/* ... */
}
// Default value for pagination
fn list_items(
&self,
#[param(default = 0)] offset: u32,
#[param(default = 10)] limit: u32,
) -> Vec<Item> {
/* ... */
}
// Extract API key from header
fn protected_endpoint(
&self,
#[param(header, name = "X-API-Key")] api_key: String,
data: String,
) -> String {
/* ... */
}
// Override location inference: force to query even though method is POST
fn search_posts(
&self,
#[param(query)] filter: String,
#[param(body)] content: String,
) -> Vec<Post> {
/* ... */
}
// Combine multiple options
fn advanced(
&self,
#[param(query, name = "page", default = 1)] page_num: u32,
) -> Vec<Item> {
/* ... */
}
}§OpenAPI Integration
- Parameters with
nameare documented with their wire names - Parameters with
defaultare marked as not required - Location overrides are reflected in OpenAPI specs