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"]}
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.
@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.