{"record":{"id":"5c50ea1c69a59111","repo":"phalcon/cphalcon","slug":"unknown-http-method-method-in-route-config","errorCode":null,"errorMessage":"Unknown HTTP method '{method}' in route config","messagePattern":"Unknown HTTP method '(.+?)' in route config","errorType":"exception","errorClass":"Phalcon\\Mvc\\Router\\Exceptions\\UnknownHttpMethod","httpStatus":null,"severity":"error","filePath":"phalcon/Mvc/Router.zep","lineNumber":2089,"sourceCode":"        }\n\n        switch method {\n            case \"\":\n            case \"connect\":\n            case \"delete\":\n            case \"get\":\n            case \"head\":\n            case \"options\":\n            case \"patch\":\n            case \"post\":\n            case \"purge\":\n            case \"put\":\n            case \"trace\":\n                let methodClass = \"add\" . ucfirst(method);\n                let route = this->{methodClass}(pattern, paths);\n                break;\n            default:\n                throw new UnknownHttpMethod(method);\n        }\n\n        if isset routeData[\"name\"] {\n            route->setName((string) routeData[\"name\"]);\n        }\n        if isset routeData[\"hostname\"] {\n            route->setHostname((string) routeData[\"hostname\"]);\n        }\n    }\n\n    protected function extractRealUri( string uri) -> string\n    {\n        var urlParts, realUri;\n\n        let urlParts = explode(\"?\", uri, 2),\n            realUri  = urlParts[0];\n\n        return realUri;","sourceCodeStart":2071,"sourceCodeEnd":2107,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Mvc/Router.zep#L2071-L2107","documentation":"Each config['routes'] entry may specify an HTTP method that selects which router add* helper is used (addGet, addPost, addPut, ...). After strtolower(), the value must be one of: connect, delete, get, head, options, patch, post, purge, put, trace, or empty (generic add). Any other string throws UnknownHttpMethod with the offending value interpolated into the message.","triggerScenarios":"\"method\": \"LIST\" or \"FETCH\" for a custom verb; typos like \"post \", \"Getx\", \"postt\"; \"method\": \"any\" or \"*\" expecting a match-all route; uppercase is fine (strtolower is applied) but whitespace and unknown words are not.","commonSituations":"Copying method lists from another framework that accepts 'ANY'; custom API verbs; trailing whitespace from spreadsheet/CSV exports; locale variants like 'POST'.","solutions":["Use one of the supported verbs (case-insensitive): connect, delete, get, head, options, patch, post, purge, put, trace","Omit 'method' entirely (or set null) for a method-agnostic route","Trim and normalize input if methods come from user data: strtolower(trim($method))"],"exampleFix":"// before\n{\n    \"routes\": [\n        {\n            \"pattern\": \"/api/users\",\n            \"paths\": {\"controller\": \"users\", \"action\": \"index\"},\n            \"method\": \"ANY\"\n        }\n    ]\n}\n\n// after\n{\n    \"routes\": [\n        {\n            \"pattern\": \"/api/users\",\n            \"paths\": {\"controller\": \"users\", \"action\": \"index\"}\n        }\n    ]\n}","handlingStrategy":"validation","validationCode":"// whitelist methods before they reach the router\nconst ALLOWED = ['', 'connect', 'delete', 'get', 'head', 'options', 'patch', 'post', 'purge', 'put', 'trace'];\n\nforeach ($config['routes'] ?? [] as $i => $entry) {\n    if (isset($entry['method'])) {\n        $method = strtolower(trim((string) $entry['method']));\n        if (!in_array($method, ALLOWED, true)) {\n            throw new InvalidArgumentException(\"routes[$i]: unsupported HTTP method '{$entry['method']}'\");\n        }\n        $config['routes'][$i]['method'] = $method;\n    }\n}\n\n$router->loadFromConfig($config);","typeGuard":"function isSupportedHttpMethod(mixed $method): bool\n{\n    if ($method === null) {\n        return true;\n    }\n    $allowed = ['connect', 'delete', 'get', 'head', 'options', 'patch', 'post', 'purge', 'put', 'trace', ''];\n    return is_string($method) && in_array(strtolower(trim($method)), $allowed, true);\n}","tryCatchPattern":"try {\n    $router->loadFromConfig($config);\n} catch (\\Phalcon\\Mvc\\Router\\Exceptions\\UnknownHttpMethod $e) {\n    $logger->error('Bad HTTP method in route config: ' . $e->getMessage());\n    throw $e;\n}","preventionTips":["There is no 'ANY' method — omit the key for method-agnostic routes","Trim and lowercase method values from external sources before validation","Document the exact verb list (connect, delete, get, head, options, patch, post, purge, put, trace) next to your routes schema"],"tags":["phalcon","router","config","http-method","validation"],"backgroundTag":"unsupported-http-method","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}