apache / openwhisk-apigateway

Apache OpenWhisk API Gateway service for exposing actions as REST interfaces.
https://openwhisk.apache.org/
Apache License 2.0
64 stars 45 forks source link

Invalid method returns 404 not 405 #257

Open akrabat opened 7 years ago

akrabat commented 7 years ago

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."}
mhamann commented 7 years ago

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.

akrabat commented 7 years ago

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 commented 7 years ago

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!)

AlanduzzZ commented 4 years ago

any updates?