Thursday, March 2, 2017

Swift Programming (Server-Side) - Kick Start..!

In this post we are going to learn some exciting stuff about Swift programming. Most of us are knowing or heard about the Swift, an additional programming language apart form Objective-C which been offered by ‘Apple Computers’ for developers and programmers to build the native app. Here we will learn quick basics about how to use Swift in Server-Side programming and play around with the web component methods or services and their integrations at high level. Also achieve bit idea of incorporating services with the cloud functionality.

Moving forward, certainly we need to set-up an environment first into the development machine. To do that, refer below links. Please be noted I did this sample in my Mac machine, optionally, it can be achievable for other platforms too –for that I encourage to check guidelines and detailed contents available under same link pages!

Important Links:

Set-up Environment:
·       MacOS Sierra – 10.12.3
·       XCode – 8.2.1
·       Rested – 2.7
·       Swift – 3.0.2
·       Perfect - Server Side Swift [Open Source - powered by Swift Programming Language Framework]
-Perfect is an open source server side Swift framework that helps you write web apps and services using Swift 3. Learn how to get started with Perfect, and create your first server side Swift web app.
-Deploying Perfect in additional environments including Heroku, Amazon Web Services, Docker, Microsoft Azure, Google Cloud, IBM Bluemix CloudFoundry, and IBM Bluemix Docker – stay tuned for future post or refer above link documentation.


Now, lets start with the steps. Once you installed all above software and tools – mentioned under set-up environment. Open Terminal in Mac machine:

$ swift -- version
$ mkdir hello-perfect
$ cd hello-perfect
$ swift package init --type executable
$ swift package generate-xcodeproj
$ open ./hello-perfect.xcodeproj/





Update Package.swift file from here:




               $ swift package update



$ swift package generate-xcodeproj
$ mkdir webroot
$ touch webroot/hello.txt

Update hello.txt file from here:


$ swift package generate-xcodeproj

Set the active scheme -> press Edit scheme -> check ‘Use custom working directory’ and pick the path of the ‘webroot’ folder which does have ‘hello.txt’ file inside before building the app or run it.





  
Copy or update main.swift file from here:

$ swift package generate-xcodeproj

Check on console the status of HTTP Server – after building or running the app, should be started with the http port number (8080). Also, we can check into the browser by typing http://localhost:8080/. It will response the string message which been programmed under main.swift file. Alternatively, you can test the result of the app via ‘Rested tool’, which is available on Apple App store free to download. Below check the output response screenshot for visibility.




The purpose of this post to learn about how to kick start server-side programming skill using Perfect Open Source Framework (i.e., powered by Swift Programming Language) - using instance of HTTPServer API method calls such as, GET, POST and others. This skill will definitely help developers and programmers to use Swift language competency on both client and server side in parallel. Also developers can get benefits to develop native mobile applications in iOS platform without having additional language skills, the approach could be considered in hybrid method architecture too with the aspect of other platform choice.

To learn or explore more about advantages, benefits and possibility of the framework, I encourage to deep dive into the above-shared links, will be useful to kick start with. Thanks!


No comments:

Post a Comment