405 Method Not Allowed
The URL exists, but you used the wrong HTTP verb. E.g., trying to POST to an endpoint that only accepts GET.
When and Why to Use It
Section titled “When and Why to Use It”Use this if you have a POST /users endpoint, and someone accidentally tries to send a GET /users request to it.
Usage Examples
Section titled “Usage Examples”import { HttpException, get } from 'shokupan';
export const getResource = get('/resource', () => { throw new HttpException('Method Not Allowed', 405);});import { Controller, Get, HttpException } from 'shokupan';
@Controller('/api')export class ExampleController { @Get('/resource') getResource() { throw new HttpException('Method Not Allowed', 405); }}import express from 'express';const app = express();
app.get('/resource', (req, res) => { res.status(405).json({ error: 'Method Not Allowed' });});import { Controller, Get, HttpException } from '@nestjs/common';
@Controller('api')export class ExampleController { @Get('resource') getResource() { throw new HttpException('Method Not Allowed', 405); }}import Koa from 'koa';const app = new Koa();
app.use(async ctx => { if (ctx.path === '/resource' && ctx.method === 'GET') { ctx.status = 405; ctx.body = { error: 'Method Not Allowed' }; }});