{"record":{"id":"234dcac93e465594","repo":"flarum/framework","slug":"methodnotallowedexception","errorCode":null,"errorMessage":"MethodNotAllowedException","messagePattern":"MethodNotAllowedException","errorType":"http","errorClass":"MethodNotAllowedException","httpStatus":405,"severity":"error","filePath":"framework/core/src/Api/Endpoint/Endpoint.php","lineNumber":117,"sourceCode":"    {\n        if (! $this->action) {\n            throw new RuntimeException('No action defined for endpoint ['.static::class.']');\n        }\n\n        return ($this->action)($context);\n    }\n\n    /**\n     * @param Context $context\n     */\n    public function handle(\\Tobyz\\JsonApiServer\\Context $context): ?Response\n    {\n        if (! isset($this->method, $this->path)) {\n            throw new RuntimeException('No route defined for endpoint ['.static::class.']');\n        }\n\n        if (strtolower($context->method()) !== strtolower($this->method)) {\n            throw new MethodNotAllowedException();\n        }\n\n        /** @var AbstractResource $collection */\n        $collection = $context->collection;\n\n        $context = $context->withModelId(\n            $collection->id($context)\n        );\n\n        if ($context->modelId) {\n            $context = $context->withModel(\n                $this->findResource($context, $context->modelId)\n            );\n        }\n\n        if (! $this->isVisible($context)) {\n            throw new ForbiddenException();\n        }","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/flarum/framework/blob/4b939f685389bfe8a380e9e28ddf305a1c66950c/framework/core/src/Api/Endpoint/Endpoint.php#L99-L135","documentation":"HTTP-method guard in the generic Api Endpoint::handle: the endpoint declares a route method (e.g. POST/DELETE), and the incoming JSON:API request used a different HTTP method for the same route, so the request cannot be dispatched to this endpoint and a 405-class MethodNotAllowedException is raised. Generic guard — the input at fault is the request's HTTP method.","triggerScenarios":"Thrown at framework/core/src/Api/Endpoint/Endpoint.php:117 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Call the endpoint with the HTTP method it declares (check the endpoint class's $method, e.g. POST for CreateEndpoint, DELETE for DeleteEndpoint).","Fix routing/client code that reuses one URL for multiple verbs incorrectly.","Handle 405 at the client and advertise allowed methods."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"4b939f685389bfe8a380e9e28ddf305a1c66950c","analyzedAt":"2026-09-15T18:09:20.879Z","contentChangedAt":"2026-09-15T18:09:20.879Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}