{"record":{"id":"6399bc9de79182c4","repo":"actix/actix-web","slug":"the-route-macro-requires-at-least-one-meth","errorCode":null,"errorMessage":"The #[route(..)] macro requires at least one `method` attribute","messagePattern":"The #\\[route\\(\\.\\.\\)\\] macro requires at least one `method` attribute","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"actix-web-codegen/src/route.rs","lineNumber":359,"sourceCode":"}\n\nimpl Route {\n    pub fn new(args: RouteArgs, ast: syn::ItemFn, method: Option<MethodType>) -> syn::Result<Self> {\n        let name = ast.sig.ident.clone();\n\n        // Try and pull out the doc comments so that we can reapply them to the generated struct.\n        // Note that multi line doc comments are converted to multiple doc attributes.\n        let doc_attributes = ast\n            .attrs\n            .iter()\n            .filter(|attr| attr.path().is_ident(\"doc\"))\n            .cloned()\n            .collect();\n\n        let args = Args::new(args, method)?;\n\n        if args.methods.is_empty() {\n            return Err(syn::Error::new(\n                Span::call_site(),\n                \"The #[route(..)] macro requires at least one `method` attribute\",\n            ));\n        }\n\n        if matches!(ast.sig.output, syn::ReturnType::Default) {\n            return Err(syn::Error::new_spanned(\n                ast,\n                \"Function has no return type. Cannot be used as handler\",\n            ));\n        }\n\n        Ok(Self {\n            name,\n            args: vec![args],\n            ast,\n            doc_attributes,\n        })","sourceCodeStart":341,"sourceCodeEnd":377,"githubUrl":"https://github.com/actix/actix-web/blob/4d435abc281842f3cbee165b6cde739e001d3a25/actix-web-codegen/src/route.rs#L341-L377","documentation":"This compile-time error fires when the `#[route(\"/path\")]` macro is used without specifying at least one HTTP method via the `method = \"...\"` option. Unlike the shorthand macros (`#[get(...)]`, `#[post(...)]`), the `#[route(...)]` macro does not imply a method, so `args.methods` remains empty and the check at line 358-363 fails.","triggerScenarios":"Writing `#[route(\"/users\")]` without any `method = \"GET\"` option. The `route` macro requires you to explicitly declare which HTTP method(s) it handles.","commonSituations":"Developers switching from `#[get(\"/path\")]` to `#[route(\"/path\")]` and forgetting to add the method option, or assuming `route` defaults to GET.","solutions":["Add at least one method option: `#[route(\"/users\", method = \"GET\")]`","Alternatively, use the shorthand `#[get(\"/users\")]` if only one method is needed","For multiple methods: `#[route(\"/users\", method = \"GET\", method = \"POST\")]`"],"exampleFix":"// before\n#[route(\"/users\")]\nasync fn users() -> impl Responder { ... }\n\n// after\n#[route(\"/users\", method = \"GET\")]\nasync fn users() -> impl Responder { ... }","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// Compile-time error. The #[route(...)] macro requires explicit method(s):\n// #[route(\"/users\", method = \"GET\")] — correct\n// #[route(\"/users\")] — incorrect (no method)\n// Or use shorthand: #[get(\"/users\")]","tryCatchPattern":null,"preventionTips":["Always include at least one method = \"...\" option when using #[route(...)]","Prefer shorthand macros like #[get(\"/\")] for single-method routes","Review the difference between #[route(...)] and #[get(...)] / #[post(...)] in the docs"],"tags":["rust","actix-web","codegen","routing","compile-time","macro"],"backgroundTag":null,"analyzedSha":"4d435abc281842f3cbee165b6cde739e001d3a25","analyzedAt":"2026-08-09T01:01:40.926Z","contentChangedAt":"2026-08-09T01:01:40.926Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}