pub async fn method_not_allowed_json(req: Request, next: Next) -> ResponseExpand description
Give axum’s bodiless 405 the JSON envelope the rest of the API uses.
The router registers GET (and one POST, for login), so any other
verb is refused by axum’s own MethodRouter — correctly, and with the
Allow header RFC 9110 requires. But it refuses with an empty body,
and docs/api.md promises every failure is JSON with a stable code. A
client that does res.json() on a failure — the normal shape of a
fetch wrapper — got a SyntaxError pointing at its own parser instead
of a 405 pointing at its verb.
The message does not name the permitted verbs, and cannot: axum
attaches Allow outside Router::layer, so this middleware never
sees it. That is the right division anyway — Allow is where a client
is supposed to look, it is per-route (/pages/ allows GET,HEAD,
/auth/login allows POST), and duplicating it into prose from here
would mean re-deriving routing knowledge that would eventually lie.
Inner headers are carried across so replacing the body never drops
one.