405 Method Not Allowed
Fault: Client
TL;DR
HTTP method (GET, POST, etc.) not allowed for this endpoint.
The request method is not supported for the requested resource.
What This Error Means
The request method is not supported for the requested resource.
HTTP method (GET, POST, etc.) not allowed for this endpoint.
Common Causes
- Using POST on GET-only endpoint
- Using GET on POST-only endpoint
- Method not implemented
How to Fix It (For Visitors)
- Contact the website administrator
How to Fix It (For Developers/Admins)
- Check API documentation for allowed methods
- Verify HTTP method in request
- Add Allow header in response
- Review route configuration
Code Examples
Here's how to return a 405 status code in various programming languages:
Python (Flask)
from flask import Flask, jsonify
app = Flask(__name__)
@app.route('/endpoint')
def endpoint():
return jsonify({"message": "Method Not Allowed"}), 405
Node.js (Express)
const express = require('express');
const app = express();
app.get('/endpoint', (req, res) => {
res.status(405).json({ message: 'Method Not Allowed' });
});
PHP
<?php
http_response_code(405);
header('Content-Type: application/json');
echo json_encode(['message' => 'Method Not Allowed']);
?>
Go
package main
import (
"encoding/json"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(405)
json.NewEncoder(w).Encode(map[string]string{
"message": "Method Not Allowed",
})
}
Java (Spring Boot)
@GetMapping("/endpoint")
public ResponseEntity<Map<String, String>> endpoint() {
Map<String, String> response = new HashMap<>();
response.put("message", "Method Not Allowed");
return ResponseEntity.status(405).body(response);
}
Ruby (Sinatra)
get '/endpoint' do
status 405
json message: 'Method Not Allowed'
end
Browser Compatibility
| Browser | Support | Notes |
|---|---|---|
| Chrome | ✓ Full Support | All versions |
| Firefox | ✓ Full Support | All versions |
| Safari | ✓ Full Support | All versions |
| Edge | ✓ Full Support | All versions |
Official Specification
This status code is defined in RFC 7231 Section 6.5.5.