I just want to point out this really funny joke that someone made to me on twitter - this was a pretty good joke, but it should give you the idea that this talk will involve more than just mobile apps.
I want to tell you a story about myself. I'm fortunate enough to have learned some new things here and there, but at the time of this story that i'm going to tell you, I only knew mobile. but, life was good! ever since apple forced me to learn Swift (or else), I was happy with functional programming !"
I had lots of contracts to work on. I earned a lot of money. things were simple, and I was living the dream. However, one day, the server dev went home sick, passing away in a bizarre gardening accident. !"
and suddenly, I was on my own. I felt the shivering cold abyss of having to figure out how to handle servers. what was I going to do now? I hadn't really dont anything with servers, so I was a bit nervous about diving into a world I knew nothing about. !
Not only that, but how would I figure out how to handle server side code, while simultaneously worrying about how to maintain a server? How will I work with a load balancer? How do I deploy to a server? WHAT WILL I DO?!?!?!?!?! !
Jenny told me about this concept called Serverless code, and thanks to the industry moving forward as quickly as it was, I was able to use this architecture with a language I knew quite well already... !
Swift! whew, that makes things a bit easier. The concept of serverless can be tremendously helpful for me who just needs to "get it done", and this came across as a bit of a lifesaver. SERVERLESS NOW WITH SWIFT!
In a word, there are still servers, but, I had to think about what my responsibility really was when it came to "serverless" development. Thankfully, Jenny was able to explain it to me with a quote that still sticks with me, and perfectly
just read the quote. “Serverless computing refers to a model where the existence of servers is simply hidden from developers. I.e. that even though servers still exist developers are relieved from the need to care about their operation. They are relieved from the need to worry about low-level infrastructural and operational details such as scalability, high- availability, infrastructure-security, and so forth.”
the server is maintained for me. Jenny explained to me that I just have to worry about what happens with the code TL;DR ▸ servers ▸ without the server maintenance
So Jenny explained, "All you have to do is write a function!" And she showed me this, telling me that there are a couple of things to point out here. func main(args: [String:Any]) -> [String:Any] { guard let name = args["name"] as? String else { return ["error" : "No name included"] } return ["output" : "Sick presentation, \(name)!"] }
1) my function must be called "main" func main(args: [String:Any]) -> [String:Any] { guard let name = args["name"] as? String else { return ["error" : "No name included"] } return ["output" : "Sick presentation, \(name)!"] }
1) my function must be called "main" 2) my parameters must be passed in as "args" func main(args: [String:Any]) -> [String:Any] { guard let name = args["name"] as? String else { return ["error" : "No name included"] } return ["output" : "Sick presentation, \(name)!"] }
But I didn't think I was done yet. I knew I could get this working on my local machine, but I knew nothing about deploying to the cloud. I mean, I only work for IBM, so cloud computing doesn't come naturally to me. So I asked how I can get this going, and she told me, "look, it's just 5 easy steps." !
she showed me these five commands. "Follow these, and you'll be ready to go", she told me. wsk action create swiftAction function.swift wsk action update swiftAction function.swift wsk action invoke swiftAction --param name David wsk action invoke swiftAction --param name David -b wsk action invoke swiftAction --param name David -b -r
first, I have to actually create the action. she told me to think of an action like a file that runs a set of functions I can type in. all I have to do is reference the file in this command, name my action, and I'm ready to go. wsk action create swiftAction function.swift wsk action update swiftAction function.swift wsk action invoke swiftAction --param name David wsk action invoke swiftAction --param name David -b wsk action invoke swiftAction --param name David -b -r
similarly, whenever I updates my code, I can update the way my action works with this command. wsk action create swiftAction function.swift wsk action update swiftAction function.swift wsk action invoke swiftAction --param name David wsk action invoke swiftAction --param name David -b wsk action invoke swiftAction --param name David -b -r
then she told me that, in order to actually run this action, I'll need to invoke it. I can specify as many parameters as I want this way wsk action create swiftAction function.swift wsk action update swiftAction function.swift wsk action invoke swiftAction --param name David wsk action invoke swiftAction --param name David -b wsk action invoke swiftAction --param name David -b -r
so I did this, and I didn't really see anything returned to me but an ID. she told me that this is because these functions are returned asynchronously. I wanted to try them out right in the CLI, so she told me to add the - b, which stands for "blocking". This makes it so that I can see all the output returned right in my cli. wsk action create swiftAction function.swift wsk action update swiftAction function.swift wsk action invoke swiftAction --param name David wsk action invoke swiftAction --param name David -b wsk action invoke swiftAction --param name David -b -r
so she told me to add a -r to my call, which stands for "result". So i added this to my command, and boom! wsk action create swiftAction function.swift wsk action update swiftAction function.swift wsk action invoke swiftAction --param name David wsk action invoke swiftAction --param name David -b wsk action invoke swiftAction --param name David -b -r
This was deliberately high level, so if you'd like to take a deeper dive into this world while you're at swift summit... WANNA BE LIKE JENNY? OF COURSE YOU DO
this lab will go, from start to finish, by setting up a swift action, calling out to an API, using Swift you already know to modify the output, and sending it back down in your response. Ideally, you'll leave the lab with a live Swift function, ready to go. HANG OUT WITH ME FROM 3:00 - 4:00 PM FOR A HANDS- ON LAB WHERE WE'LL GET THE PRICE OF BITCOIN!
as a pre-req, go here and sign up for an account, so that linking your CLI is easier to do than otherwise. its free! https://console.bluemix.net/registration/