hono icon indicating copy to clipboard operation
hono copied to clipboard

If path exists but method is not allowed hono should response with a 405 (method not allowed) status

Open qoomon opened this issue 9 months ago • 3 comments

What is the feature you are proposing?

If path exists but method is not allowed hono should response with a 405 (method not allowed) status, instead of a 404

qoomon avatar May 06 '24 11:05 qoomon

We can write it like the following:

app
  .get('/get', (c) => {
    return c.text('get')
  })
  .all((c) => {
    return c.text('Method not allowed', 405)
  })

I don't prefer adding the feature to Hono's core because we don't want to increase the code.

yusukebe avatar May 06 '24 11:05 yusukebe

Thanks for the solution. I still think this should be the default behavior because 404 is kinda wrong if the path exists.

qoomon avatar May 06 '24 19:05 qoomon

Thanks for the solution. I still think this should be the default behavior because 404 is kinda wrong if the path exists.

You shouldn't tell the client that they cannot use the method, 405 Method Not Allowed only effective for Development environment, you can use 401 Unauthorized or 404 Not Found for Client.

405 Method Not Allowed should only be used if you don't support the method. It shouldn't be used to tell the client that they cannot use this method.

So make it as default was not a good option I think.

fzn0x avatar May 06 '24 20:05 fzn0x

I think you are right (again 😁). Thanks for explaining, I learned a lot.

qoomon avatar May 07 '24 08:05 qoomon