openwhisk-apigateway icon indicating copy to clipboard operation
openwhisk-apigateway copied to clipboard

Invalid method returns 404 not 405

Open akrabat opened this issue 7 years ago • 4 comments

Given an API Gateway set up to only accept GET, if I try to POST to it, I get a 404 back.

I should get a 405 as the resource exists (i.e. was found), but I'm not allowed to access it with this method.

$ wsk api create /hello / GET hello
ok: created API /hello/ GET for action /_/hello
https://service.eu.apiconnect.ibmcloud.com/gws/apigateway/api/d12...b12/hello/

$ curl -I -X POST https://service.eu.apiconnect.ibmcloud.com/gws/apigateway/api/d12..b12/hello
HTTP/1.1 404 Not Found
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS
Access-Control-Allow-Origin: *
Content-Type: application/json; charset=utf-8
Date: Sun, 17 Sep 2017 19:07:37 GMT
Server: openresty
Content-Length: 62

{"status":404,"message":"Error: Whoops. Verb not supported."}

akrabat avatar Sep 17 '17 19:09 akrabat

If you implemented a route in Express that had a GET but no POST, what would you get? I believe the Method Not Allowed error is for a method + route that does exist, but has been disabled for some reason.

mhamann avatar Sep 17 '17 19:09 mhamann

I don't use JS, so I haven't a clue what Express does.

The specification seems quite clear that 405 is to be used when the method is not supported by the resource (/hello in this case):

The 405 (Method Not Allowed) status code indicates that the method received in the request-line is known by the origin server but not supported by the target resource.

akrabat avatar Sep 17 '17 20:09 akrabat

Googling, I see that Express doesn't do this because it's too complicated to do in their codebase: https://github.com/expressjs/express/issues/1895#issuecomment-33279114

API Gateway shouldn't have this problem as it knows all the valid methods for any given path as we have to create them... (of course, I'm making assumptions here!)

akrabat avatar Sep 17 '17 20:09 akrabat

any updates?

AlanduzzZ avatar May 11 '20 14:05 AlanduzzZ