1

Hello everyone I have deployed a function on IBM cloud and I am calling it via web api however all the function works fine except for those that involve route parameters as I am unable to extract them. I am using the serverless framework and when calling the variable __ow_path it returns empty. Any help will be highly appreciated. Thanks.

serverless.yml file:

getById:
  handler: handler.getById
  overwrite: true
  annotations:
    web-export: true
  events:
    - http: 
        method: GET
        path: /users/{userid}
        resp: http

handler.js file:

module.exports.getById = async (params) => {
    return {
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({
            params,
            msg: params.__ow_path,
            created: new Date()
        }),
        statusCode: 200
    }
}
James Thomas
  • 4,303
  • 1
  • 20
  • 26

1 Answers1

1

Please upgrade the serverless-openwhisk package to version 0.18.3. This is due to a known bug introduced in 0.18.

The example above is valid.

James Thomas
  • 4,303
  • 1
  • 20
  • 26
  • After updating to 0.18.3 I am getting the path but it does not return a 404 if route is not found. For example my route is `users/{userid}` but on accessing the following route `users/{userid}/details` it still returns the previous endpoint instead of a 404. Also I was wandering if there's a way to get path params as key value pairs. – Syed Hammad Ahmed Feb 28 '19 at 06:17
  • Sub-paths (`/details`) on existing paths need to handled manually by the action. There is an open issue to provide path params as explicit parameters (https://github.com/apache/incubator-openwhisk/issues/3593) but this isn't implemented yet. – James Thomas Feb 28 '19 at 09:18
  • One more thing, the param `__ow_body` is also not accessible in post request. The req body params are present but they are not wrapped inside `__ow_body`. – Syed Hammad Ahmed Mar 01 '19 at 06:31