This is a native SDK for interacting with OpenWhisk.
OpenWhisk is a serverless platform that operates on the basis of creating “actions” and invoking them. To learn more about how to use OpenWhisk, please go here.
Mantra
The goal is to never, ever, ever return raw data to the consumer of OpenWhisk. Ever. Native objects, forever.
Setup
You can integrate this SDK with Swift Package Manager. Add the following line to your Package.swift file:
There are two parameters in this call, blocking and resultOnly, which could elicit three possible responses. OpenWhisk is usually asynchronous in nature, which means that default behavior will return a token called activationId to be redeemed for a response when the action completes its work. The default value for both of these parameters in this function is false.
if blocking is set to false, then a token will be returned to redeem later (this functionality has not yet been built into the SDK)
if blocking is set to true, and resultOnly is set to false, then the action will complete and send a full response, including the result of the function in a native context specified per your response object
if blocking is set to true, and resultOnly is set to true, then the action will complete and send only the result of the function minus the metadata of the invoked action.
Plans
I am fully aware that there is already a Swift SDK for OpenWhisk here. Can this be better? Time will tell.
Thank you to James Thomas for peer pressuring me into trying this on a flight from Boston to Austin.
Openwhisk SDK for Swift
This is a native SDK for interacting with OpenWhisk.
OpenWhisk is a serverless platform that operates on the basis of creating “actions” and invoking them. To learn more about how to use OpenWhisk, please go here.
Mantra
The goal is to never, ever, ever return raw data to the consumer of OpenWhisk. Ever. Native objects, forever.
Setup
You can integrate this SDK with Swift Package Manager. Add the following line to your
Package.swift
file:After you update your manifest, type
swift build
in your command line, and the project should resolve its dependencies.In your project, you need to first set up an instance of
Agent
. You must set four properties when using anAgent
instance:After that, you can make requests with your instance of
Agent
.Functionality
getActions
You can retrieve the list of actions in your namespace like so:
The result passed into the closure is a collection of type
Action
. Please check the class documentation for information on this object.getActionDetail
If you have an instance of
Action
, you can choose to get details on that action, such as source code, with the following function:The result passed into the closure is an instance of type
ActionDetail
. Please check the class documentation for information on this object.invoke
If you have an instance of
Action
, you can invoke it in a number of ways. There are two pre-requisites for invoking an action.Codable
.Codable
As an example, let’s assume I have an action that retrieves the price of Bitcoin given a country code. In JSON, my input looks like this:
I would need to make a corresponding
Codable
object like so:Let’s also assume that my potential output, in JSON, would look like this:
I would then need to make a corresponding
Codable
type like so:Having both of these defined, I can then invoke such an action like so:
There are two parameters in this call,
blocking
andresultOnly
, which could elicit three possible responses. OpenWhisk is usually asynchronous in nature, which means that default behavior will return a token calledactivationId
to be redeemed for a response when the action completes its work. The default value for both of these parameters in this function isfalse
.blocking
is set tofalse
, then a token will be returned to redeem later (this functionality has not yet been built into the SDK)blocking
is set totrue
, andresultOnly
is set tofalse
, then the action will complete and send a full response, including the result of the function in a native context specified per your response objectblocking
is set totrue
, andresultOnly
is set totrue
, then the action will complete and send only the result of the function minus the metadata of the invoked action.Plans
I am fully aware that there is already a Swift SDK for OpenWhisk here. Can this be better? Time will tell.
Thank you to James Thomas for peer pressuring me into trying this on a flight from Boston to Austin.