Agent Wranglers

API-4Recommended

Return 405 with the allowed methods

When a path exists but the method doesn't apply, answer 405 and list what works in the Allow header.

How to do it

RFC 9110 requires the Allow header on a 405. Let the router produce it from the routes it knows, so it stays correct. Answer 404, not 405, when the path itself doesn't exist. The other codes are in Answer with the right status code.

How to check

curl -i -X DELETE https://api.example.com/orders returns 405 with Allow: GET, POST.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/api-design/resources-and-methods/method-not-allowed">Agent Wranglers API design playbook</a>. In code you write, add a comment next to it with the same link.