Plumber: Requests to valid endpoints with an incorrect request method should return HTTP 405 instead of HTTP 404

Created on 1 Oct 2019  路  4Comments  路  Source: rstudio/plumber

Example application

Suppose we have the following API:

srv <- plumber::plumber$new()
srv$handle("POST", "/submit", function(req, res) {
  # TODO: Actual work.
  res$headers[["Content-Type"]] <- "text/plain"
  res$body <- "Submitted"
  res
})
srv$run(host = "0.0.0.0")

If you send a GET request to this API (instead of the POST request it is expecting) you see the following (e.g. with curl):

$ curl -sv -X GET localhost:7312/submit
> GET /submit HTTP/1.1
> Host: localhost:7312
> User-Agent: curl/7.58.0
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Date: Mon, 30 Sep 2019 22:15:12 GMT
< Content-Type: application/json
< Date: Mon, 30 Sep 2019 10:15:12 PM GMT
< Content-Length: 38
<
{"error":["404 - Resource Not Found"]}

Describe the problem in detail

There is a well-known and well-supported HTTP status code for the specific issue of "this URI is valid but the method is not", namely 405 Method Not Allowed. It would be nice if Plumber could support returning this method instead of falling back to 404.

From a cursory look at how routing is implemented, this should be quite possible. It might require that users add a new error handler, though.

advanced low bug

All 4 comments

@schloerke Does tagging this issue as a bug mean that you would accept a PR?

Yes! I鈥檒l be getting back to plumber here soon.

To be clearer... You鈥檝e found very good bugs. I鈥檇 be happy to have any of your contributions.

Oh, that's very kind. I wasn't intending to sound impatient with my comment, I was actually just unsure about what the tags implied.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

emmanuelchevallier picture emmanuelchevallier  路  3Comments

shangfr picture shangfr  路  5Comments

Jube-Dev picture Jube-Dev  路  3Comments

actuarialvoodoo picture actuarialvoodoo  路  6Comments

alexzaytsev-newsroomly picture alexzaytsev-newsroomly  路  6Comments