DioxusLabs/dioxus · error · syn::Error
HTTP method not specified in macro or in attribute
Error message
HTTP method not specified in macro or in attribute
What it means
The mirror of the 'specified both' error: the generic `#[route]` macro was used and no HTTP method token was given in the attribute, and no method-specific wrapper (`#[get]` etc.) supplied one either. Dioxus cannot register a handler without a verb, so compilation stops (packages/fullstack-macro/src/lib.rs:736-741).
Source
Thrown at packages/fullstack-macro/src/lib.rs:737
"Cannot have multiple query parameters when one is a catch-all",
));
}
if let Some(options) = route.oapi_options.as_mut() {
options.merge_with_fn(function)
}
let method = match (method_from_macro, route.method) {
(Some(method), None) => method,
(None, Some(method)) => method,
(Some(_), Some(_)) => {
return Err(syn::Error::new(
Span::call_site(),
"HTTP method specified both in macro and in attribute",
));
}
(None, None) => {
return Err(syn::Error::new(
Span::call_site(),
"HTTP method not specified in macro or in attribute",
));
}
};
Ok(Self {
method,
route_lit: route.route_lit,
path_params: route.path_params,
query_params,
oapi_options: route.oapi_options,
prefix: route.prefix,
server_args: route.server_args,
})
}
pub fn query_is_catchall(&self) -> bool {View on GitHub (pinned to 393d190a80)
Solutions
- Add a method token to the attribute: `#[route(POST, "/submit")]`.
- Or switch to a method-named macro: `#[get("/items")]` / `#[post("/items")]`.
- Prefer the method-named macros for single-verb handlers — they make omission impossible.
Example fix
// before
#[route("/submit")]
async fn submit(form: Form<Data>) { ... }
// after
#[route(POST, "/submit")]
async fn submit(form: Form<Data>) { ... } Defensive patterns
Strategy: validation
Validate before calling
# Fail when a generic #[route(...)] attribute has no HTTP method token
rg -n '#\[route\((?![^)]*\b(GET|POST|PUT|DELETE|PATCH|HEAD|OPTIONS|PATCH)\b)[^)]*"' src/ && \
{ echo 'ERROR: #[route(...)] without HTTP method'; exit 1; } || true Prevention
- Default to method-named macros (#[get], #[post]) — omission becomes impossible.
- Route literals always carry the verb in code review checklists for new endpoints.
When it happens
Trigger: `#[route("/submit")]` with no method token; `#[route("/submit", summary = "x")]` where all arguments are route/oapi fields and the verb was forgotten; deleting a method token while refactoring and not noticing until build.
Common situations: Writing a new endpoint and forgetting the verb; assuming a default (e.g. GET) exists — it does not; migrating from axum's `#[axum::routing::get]` style where the verb lives elsewhere.
Related errors
- HTTP method specified both in macro and in attribute
- Use `api_route` instead of `route` to use OpenAPI options
- path parameter `{}` not found in function arguments
- query parameter `{}` not found in function arguments
- Cannot have multiple query parameters when one is a catch-al
AI-assisted analysis of DioxusLabs/dioxus@393d190a80 (2026-08-16).
Data as JSON: /api/errors/0b40e4db69fbb12a.
Report an issue: GitHub.