Raymond Camden

Developer Advocate for IBM

Time for another quick OpenWhisk tip. As you know (or may know!), when you create an OpenWhisk web action, you can pass parameters via the query string or via a form post. So consider the following trivial action:

The good news is that this is pretty simple to support. OpenWhish will pass this information to your action as args.__ow_path. OpenWhisk actually passes a bunch of things you can read about here, but for our purposes, the __ow_path value is all we need. So consider this new version:

All I've done is look for the path, see if it has length, and then I parse it. Now - in my particular case I'm assuming only one valid path: /name/X. Obviously you could write the code to be a bit more generic, perhaps in the form of: /name/value/name/value etc. But to keep it simple I just look for /name/X and if that matches, set args.name to it. The result works perfectly:

Heh, oops. Almost. So you may have noticed I used decodeURIComponent above, and it works correctly if you encode spaces with %20:

So from what I've seen in my research, the plus sign is not meant to be decoded, and it may actually be part of the original string. So what you do here is up to you really. In this particular use case where I'm working with names, it would probably be safe to go ahead and replace plus signs with spaces:

args.name = decodeURIComponent(parts[2]).replace(/\+/g, ' ');

I hope this helps! As a quick aside, the URL in my tests includes safeToDelete. That has nothing to do with the post. I'm just trying to use that package as a way to flag to myself actions I can safely delete later. (As you can imagine, I've got a bunch of crap up now on OpenWhisk and I'm starting to feel like I need to clean up a bit!)