honojs/hono

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

Closed this issue · 4 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

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.

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

fzn0x commented

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.

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