Sins are coming along with the summer. Since I’m a curious human being, I cheated on my beloved iOS development and went on a ride with Swift server side programming 🎢.

As you may have read in the prologue, I have strong intent to learn server side development. With this knowledge in my pocket, I could hopefully work with server side developers more fluently and could design better apps together. It’s always good to get know the other’s point of view 👀 but no, I don’t want to live in the shadow on the long run.

darkside

And I defenetly don’t want to be a guy who develops something that the users don’t interact with directly. So when your friends ask:

– "Ohh, it's a really cool app! What was your role in it?"
– "Errr, no you can't see that part, I developed its soul! 👻"
– "Yeah, sure.😏"

“Trying” Kitura

Hoping I could rapidly learn the basics and see best practices, I participated in a ‘Server side with Swift’ workshop recently. But it came to light really fast that it was going to be more of a product promotion than an actual workshop 🤷‍♂️. The event was organized by IBM Hungary so they showed us how to setup an account on their Bluemix cloud service. We were clicking in the browser hours long, setting up a hosting environment with database, creating a repo containing both server and mobile application projects, and waiting for the Bluemix site to load pages in between 20 and 45 seconds ⏳. We only developed copied about 20 lines code to create a so called API which handles only one GET request with no routing ⬇️. The whole event was very unprofessional, like they hadn’t even tested it before. For example we were told to install MySQL, which we didn’t use at all 🤦. Unfortunatelly I can’t say anything about Kitura and Swift backend programming, but it was such a bad experience with IBM, that I’m not going to use any of their product for a very long time 🙅‍♂️.

Experiences with Perfect

Since most of the benchmarks reveals that Perfect is a perfect👌 web server framework, I decided to try it out. After the ‘workshop’, it was a great experience to download an example project, which just works and includes even API versioning, routing, etc .

But strange things started to happen when I was exploring an user authentication example. I called the /api/v1/register endpoint with a raw JSON body { username: "danieltmbr", password: "Pass123!" } and the response was an error: “Missing username or password”. Prepare for a debug session 🐛.

  1. Strange thing numero uno:
    /// The parsed and decoded query/search arguments.
    var queryParams: [(String, String)] { get }
    
     /// Any parsed and decoded POST body parameters.
    var postParams: [(String, String)] { get }
    
     /// Returns all GET or POST parameters.
    public func params() -> [(String, String)] {
     let a = self.queryParams + self.postParams
     return a
    }
    

    In case you missed it: [(String, String)]. Why❓❓❓ A tuple array instead of a dictionary. Why is it better to iterate through a tuple array than finding a value by key in O(1) step? Yes, they do that. It’s just icing on the cake that every parameter is handled as string 🍰. And I’m not even mad about the well named variable, called “a”.

  2. Strange parameter parsing: Post params in a tupple The whole json become the ‘key’ string of the first tuple of the params array. With no ‘value’ 😒.

  3. It was probably my bad:
    It appeared that I wasn’t thorough enough, since the readme contains the following information:
    Included JSON Routes POST /api/v1/register (with username & password form elements)

    So I had to change the ContentType to x-www-form-urlencoded. OK, it contains keys and values, but not exaclty JSON.

Anyway, that was the point where I thought, maybe it was not that ‘Perfect’ at all. I’m defenetly not giving up on Swift backend programming, but I put it on hold for a while.

Now I’m heading to the competition’s solution: Google’s Golang🤞.