Both HTTP 405 and HTTP 501 relate to unsupported HTTP methods, but they differ in scope and protocol responsibility.
Route-specific vs. Global capability
- HTTP 405 Method Not Allowed (4xx): The server knows the HTTP verb (e.g.,
POST), but the target route only allowsGETandHEAD. The server must send anAllowheader listing supported verbs. - HTTP 501 Not Implemented (5xx): The server does not support or recognize the method anywhere across any route on the server (e.g., custom verbs like
PURGEor WebDAVPROPFIND).
How to test with curl
curl -i -X POST https://api.example.test/v1/read-only-route
Key takeaway
Return 405 Method Not Allowed when a specific URL route forbids a standard HTTP method. Return 501 Not Implemented when the server software lacks the underlying capability to process the method globally.