# HTTP 405 Method Not Allowed — Meaning, Causes & Fixes

> The URL exists, but it doesn't support the HTTP method used.

405 means the route is right but the verb is wrong — a POST to an endpoint that only accepts GET, or a DELETE the server doesn't implement for that resource. The response must include an `Allow` header listing the methods the resource does support.

- Class: 4xx Client Error
- Retry: No — change the request first
- Cacheable by default: yes
- Defined in: [RFC 9110 §15.5.6 — 405 Method Not Allowed](https://www.rfc-editor.org/rfc/rfc9110.html#section-15.5.6)

## Example response

```http
HTTP/1.1 405 Method Not Allowed
Allow: GET, HEAD
Content-Type: application/json
Content-Length: 30

{"error":"Method Not Allowed"}
```

## Common causes

- Sending POST to a static file or a read-only endpoint.
- A form submitting to a URL whose handler only defines GET.
- Next.js route handlers: `route.ts` exports `GET` but not `POST`.
- Static hosts (S3, GitHub Pages, most CDNs) only serve GET and HEAD.

## How to fix it

1. Read the `Allow` header in the response to see which methods are accepted.
2. Define a handler for the method on the server, and for OPTIONS if browsers call the endpoint cross-origin.
3. Point form submissions and API calls at a server endpoint, not a static file.

## Send a 405 from your server

### Express

```
res.set("Allow", "GET, HEAD");
res.status(405).json({ error: "Method Not Allowed" });
```

### Next.js route handler

```
return Response.json({ error: "Method Not Allowed" }, { status: 405, headers: { "Allow": "GET, HEAD" } });
```

### Flask

```
return {"error": "Method Not Allowed"}, 405, {"Allow": "GET, HEAD"}
```

### Go net/http

```
w.Header().Set("Allow", "GET, HEAD")
http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed)
```

### nginx

```
add_header Allow "GET, HEAD" always;
return 405;
```

## FAQ

### 405 vs 404?

404: no such resource. 405: the resource exists, but not for this method. Return 405 with an Allow header so clients can correct themselves.

### 405 vs 501?

405: this resource doesn't support the method. 501: the server doesn't implement the method for any resource.

## Related status codes

- [404 Not Found](https://www.devkult.com/http/404.md)
- [501 Not Implemented](https://www.devkult.com/http/501.md)
- [400 Bad Request](https://www.devkult.com/http/400.md)

Open the interactive page: https://www.devkult.com/http/405