Kong / kong-plugin-openwhisk

A kong plugin to invoke OpenWhisk action (serverless functions as service).
Apache License 2.0
9 stars 12 forks source link

Question on Routes #9

Open riteshapatel opened 5 years ago

riteshapatel commented 5 years ago

I have Kong configured with this plugin. I have a sample OW action and a POST route configured with Kong. The plugin is enabled at Service level.

I am only able to send POST requests. I tried to get the action invoked through GET request but I keep getting "method not allowed". May be I need to have headers sent back from OW action? Not sure.

In short I want to configure a Kong route /helloworld, with GET, POST, PUT methods. Does the plugin support invoking different OW actions for the same endpoint based on the request type?

I did see WebAction(s) for OW that allows to detect the method type via __ow_method. Not sure if that is the only way and most importantly does Kong plugin support WebAction(s)?

Here is some sample code I have used.

# create kong service
curl -i -X  POST http://localhost:8001/services/ \
   --data "name=api" \
   --data "url=http://localhost"

# create kong route
curl -i -f -X  POST http://localhost:8001/services/api/routes/ \
   --data "paths[]=/handshake"

# enable openwhisk plugin on the service 
curl -i -X POST http://localhost:8001/services/api/plugins \
    --data "name=openwhisk" \
    --data "config.host=localhost" \
    --data "config.port=31001" \
    --data "config.service_token={key:value}" \
    --data "config.action=handshake" \
    --data "config.path=/api/v1/namespaces/guest"

# invoke action via kong endpoint
curl -i -X POST http://localhost:8000/handshake -H "Host:localhost" --data "name=Ritesh"

HTTP/1.1 200 OK
Content-Type: application/json
Connection: keep-alive
Access-Control-Allow-Methods: GET, DELETE, POST, PUT, HEAD
Access-Control-Allow-Origin: *
Date: Sun, 10 Feb 2019 04:16:25 GMT
X-Request-ID: L9XcZZJ4dVC5dL0cie4HEYLcb73vhv0i
Connection: keep-alive
Server: kong/0.14.1
x-openwhisk-activation-id: 2acf765b56f345b78f765b56f3e5b7da
Access-Control-Allow-Headers: Authorization, Origin, X-Requested-With, Content-Type, Accept, User-Agent
Content-Length: 55
Via: kong/0.14.1
{"greeting":"Hello Ritesh!","method":"no method found"}

Above example is only with POST. I need to detect and invoke GET, PUT, DELETE (if applicable).

Any help is appreciated.

Thank you

Ritesh

rabbah commented 5 years ago

This is related to #5. The gateway needs to proxy to web actions to support other verbs, more content-types, and custom status codes.