Polyglot with Open Source and Serverless

Aug 3 · 3 min read

Create Actions

function main(params) {
var text = params.text || "";
var words = text.split(' ');
return {words: words}
struct Input: Codable {var words: [String]?}struct Output: Codable {let message: [String]}func main(param: Input, completion: (Output?, Error?) -> Void) -> Void {var result = Output(message: [] )if let words = param.words{result = Output(message: words.reversed() )}completion(result, nil)}
import sysimport jsondef main(dict):print('dict ' + json.dumps(dict))if "message" in dict:   return {'message': ', '.join(dict['message'])}else:   return { 'message': [] }
wsk action create splitjs splitjs.js
wsk action create reverseswift reverseswift.swift
wsk action create joinpy joinpy.py

Testing our actions individually

$ wsk action invoke splitjs -r -p text "hello world"{
"words": [
$ wsk action invoke reverseswift -r -p words '["hello","world"]'
"message": [
$ wsk action invoke joinpy -r -p message '["world", "hello"]'
"message": "world, hello"

Creating a sequence

wsk action create split-reverse-join  --sequence splitjs,reverseswift,joinpy
$ wsk action invoke split-reverse-join -r -p text "Hello World"
"message": "World, Hello"

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade