Path Variables for OpenWhisk API's

I am using the OpenWhisk provider for Serverless, and am using the IBM Cloud implementation of OpenWhisk.

I am trying to create a REST API. One representative piece of this API would deal with categories. I’d like endpoints like:

GET /categories
GET /categories/{categoryId}

The first endpoint returns a collection of categories, and the second returns one specific category.

The first endpoint is working fine. No problem. I’m having trouble, however, getting the second endpoint to work. I tried with yml like the following:

    handler: handler.categories
      web-export: true
      - http:
          path: categories/{categoryId}
          method: get
          resp: http

but I received an error when running sls deploy -v:

Serverless: Deploying API Gateway Route: {"relpath":"categories/{categoryId}","operation":"get","responsetype":"http","action":"/_/categories-dev-categories","basepath":"/categories"}

  Serverless Error ---------------------------------------

  Failed to deploy API Gateway route (categories/{categoryId}) due to error: POST Returned HTTP 502 (Bad Gateway) --> "API creation failure: Cannot read property 'name' of undefined"

  Get Support --------------------------------------------

  Your Environment Information -----------------------------
     OS:                     darwin
     Node Version:           8.9.4
     Serverless Version:     1.26.1

If I omit /{categoryId} from the path, then the endpoint is successfully created but only works for exact matches with /categories (i.e. my first endpoint). Any deviation from it results in 404 errors. Reasonable enough but not what I need here.

I was able to create an API endpoint that meets my needs with:

bx wsk api create /categories /categories get categories-dev-categories --response-type http

This is not identical to the /categories/{categoryId} endpoint I described above because it lacks the path variable, but it works ok because it accepts anything after /categories/ and captures it in the __ow_path variable so I can parse __ow_path and process accordingly.

I am hoping to be able to create this endpoint in Serverless so I don’t need to be running OpenWhisk commands outside of Serverless. I’d prefer to deploy with a single Serverless command rather than with a Serverless command followed by a collection of OpenWhisk API calls.

Any suggestions? Am I doing something wrong?

Thanks for your help!

There’s an open issue to support this feature here:

This is due to the OpenWhisk client library not supporting this feature. Once this PR is merged and a new version is released, it should automatically be working.