Server Side Swift vs. The Other Guys — 1: Input

The Frameworks

  • Vapor (Swift)
  • Ruby on Rails (Ruby)
  • Laravel (PHP)
  • Express (JavaScript)
  • Django (Python)
  • Spring (Java)

The Test

The test consists of parsing the following JSON input and fetching the 2nd user’s identifier as an integer.

{
"name": "Test",
"users": [
{ "id": 1337, "email": "foo@gmail.com" },
{ "id": 42, "email": "bar@gmail.com" },
{ "id": 500, "email": "baz@gmail.com" },
]
}
{
"second_user_id": 42
}

Aside

I have only developed server-side software using Swift, JavaScript, and PHP before this test. For the rest of the frameworks, it was my first attempt, and it took a lot of Googling around.

Vapor (Swift)

As a contributor to Vapor, it was very easy for me to complete the test. It took less than two minutes in total.

Paw REST Client with “The Test” Loaded

Ruby on Rails (Ruby)

I have never used Rails before, so it took a long time to get set up and get my brain wrapped around Ruby.

Ruby on Rails
params[:users][1][:id]
post ‘input’ => ‘input#input’

Laravel (PHP)

Creating a new Laravel project only took a few minutes, and the self packaged PHP server was quick to create a development environment.

Laravel

Express (JavaScript)

Express was the easiest of the non-Swift frameworks to setup. It was also the fastest, returning in 3ms.

Express

Django (Python)

Python was interesting. I was able to catch the KeyError, so indexing into the JSON data could be done in one line. But checking for an integer value had to be done as a separate step.

Django

Spring (Java)

Last but not least is Spring. This one was the hardest to get set up and took the most steps to pass the test. Java really wants to force you to use classes for your JSON. This is a good idea for big projects, but there should be a simpler way.

Java NullPointerException

Conclusion

It’s clear that something simple like reading and responding JSON could be made better in a lot of the popular web frameworks out there. The ability to access nested request data easily and without worrying about crashes is essential to every day web development. Swift makes some of these basic, repetitive tasks more concise, expressive, and safe. It’s also a lot faster.

--

--

Creating modular server side software with Swift.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
VAPOR

VAPOR

Creating modular server side software with Swift.