Monday 31 October 2016

Server Side Swift Development with Kitura



Hello developers…
 
How many of you find swift as your favorite programming language?  What if your favorite swift could make you now a full stack developer. Yes!!  swift is now extended for server side development. Developers, it’s time to reduce your dependency on Java (No offense Java fans).  I am happy to share here my initial experience, learning and challenges with this new born baby.

My journey with Kitura & server side swift started with WWDC 2016 held at San Francisco, California. Ever since I started working on iOS technology & swift, I was carrying a thought that – Java is the only most powerful full stack programming language. It really sounded wow when I first heard about enabling swift as a server side programming language. It was at WWDC, I came to know that IBM has come up with a powerful framework “Kitura” for server side web services and web applications.  This boosted my excitement towards Kitura with my bigger vision to become a full stack developer. Thanks to server side swift and Kitura.

There are various other toolkits and frameworks for server side swift such as Perfect, Vapor etc., but Kitura is close to me. It’s like my first ever pencil to write Alphabets And yea it’s a bonus when the product is from an enterprise pioneer , IBM .

Understanding Kitura basics – Where to Start & How

For many of the beginners from iOS App development team or a node.js api development team, server side swift could be interesting but may not be finding a way to start, try it out and work.

Are you one among them?
Becoming a full stack developer could be many of the developer’s goal , but most of them are focused to backend or just front end in their day today work life. Typically, your role could be …

"I am a front end iOS app developer who knows swift but don’t have any idea on api development"  (or)
"I am a backend api developer and have written a lot of micro services in node.js or plain java kind of language that connects with different types DB, but Kitura? because I don’t know swift"

It’s easy. Let me walk you through simple steps that helps us to start into Kitura based development.


Pre-requisites:
1.   Learn to work with Git repository. Get comfortable with some basic git commands.  Here is the Link –

2.   Bluemix & CF commands – Know the basics of Bluemix. How to push and deploy an application to the bluemix cloud platform. Know about cloud foundry commands to work with blue mix.  Here are some useful links



Let’s start...
Before we begin with Kitura, let us know about the power of swift to why it could be a better programming language for server side development and understand its key features.

       Swift is focusing towards enterprise development ecosystem
       Swift is Open Source - Swift 3.0 is the current required version for server side development.
       It runs on Linux / Mac OS
       Server Swift is natively compiled & fast compared to JS/Java code
       It consumes Low Memory & good for cloud workloads.
       Build time & No of average threads is less when compared to JS based runtimes.
       The base is the Package Manager, similar to NPM for node.js. But unlike node.js, package manager doesn’t have a centralized repository.

 

What is Kitura. How it works?  

A light-weight web framework written in Swift, that allows    you to develop web services with complex routes, easily. 


For node.js developers – This is like an 'Express' framework for node.js
For iOS developers – This is like a Alomofire framework built using swift and makes the server side web service development easy.

Kitura is a base web framework that supports HTTP. We can bind several other supporting frameworks from the Package Manager to develop the complete component.


Kitura Package Manager

Open source and available at https://github.com/IBM-Swift . Discover the many new libraries, modules, and packages for Kitura based development.

Where to start?

You can start with the below starter sample pack. Git clone the below repository and start explore, modify and experiment before you consume other frameworks.

Project Structure

The project is well structured and organized as given below.
a.    Public folder contains the resources required for the web application like HTML, images etc.
b.   Sources contains the folder, aka Modules, which will contain a “main.swift“ file . This is the start of the project. More like a Main.java / app.js / AppDelegate.swift.
c.    Package.swift is the dependency file where all the other dependent frameworks/packages are defined. This gets bounded & linked at swift compile.
Note: Every time a new package is defined, a swift build is needed to link them. 
d.   Manifest.yml is the property kind of file that defines the deployment configuration information used when deployed through cloud foundry.

How to Deploy & Run?

In a Linux/ Mac machine, Kitura projects can be deployed and run locally to complete the development before we push it to the server that supports swift runtime.

IBM Bluemix is one of the cloud environment that supports swift runtime and recommended for Kitura based deployment. 

Below is the bluemix URL.

A 30 days trial account can be setup on registration if you don’t have a bluemix account.
Bluemix Kitura starter pack can be downloaded from the below public Git link .

The server deployment & management can be done via
       Cloud Foundry Command Lines

       IBM Cloud Tools (ICT) for swift

       Bluemix Portal Monitor and work with Instance, services etc.


                       http://cloudtools.bluemix.net/

 








I hope that this would have given some start point for the server side swift development. I will be extending my blog on common issues and how to fix them.

Feel free to comment below for any questions on                 suggestion.
   
Sangeeth