قالب وردپرس درنا توس
Home / IOS Development / Vapor vs. Kitura: Selecting a Server-Side Swift Framework

Vapor vs. Kitura: Selecting a Server-Side Swift Framework



Server-side Swift is an exciting platform that brings clarity, performance and compiler-driven type security from Swift to the modern web. Designed by Swift's unique forces, a rich ecosystem of frames has evolved since Apple announced Swift's open purchase. If you come from the iOS development and consider server-side Swift, one of the first questions you will probably ask is: "What framework should I choose and why?"

If it sounds like you, read on. In this post you will see a comparison of the two most popular Server page Swift frames: Steam and Kitura .

Compared to traditional web frames for languages ​​like JavaScript, Ruby and PHP, Dapor and Kitura's deep Swift-based communities are clear and convincing. Both frameworks actively contribute to the Swift community as a whole – especially to Swift Server Work Group (SSWG).

When looking side by side, each framework has a distinct personality, philosophy and approach that clearly distinguishes it from the other. These differences in perspective and approach will be the main focus of this post. Both Kitura and Vapor are powerful and polished frames with plenty to offer. Finally, the answer to the question is, "What framework is right for me?" Will be based on a secondary question: "Which one best fits my own approach and priorities?" Let's dive in!

Commonalities

Both Kitura and Damp share important lessons and organizational practices built up over many years with PHP, JavaScript and Ruby web frame development. In particular, both have a recognizable top-level organization that will look to almost any developer familiar with the model viewer (MVC) pattern. Here is a side-by-side view of two simple Steam and Kitura projects:

Both clearly clarify the separation of concerns by having different sections for views, models and the "glue" code. There are several common features such as type of security and compilation .

Type Security

Just as in iOS and macOS, server-side Swift is a safe language. Swift's type security is enforced by the compiler at a deep level, and in a web development context this separates both Vapor and Kitura from modern frames based on JavaScript, Rails, PHP and many other languages.

Swift's type system can basically be disturbing to developers who did not use security requirements. But Swift leads developers to think more precisely. In a server-side context, the end result is the web code that is more immune to many of the most harmful errors common to other web frames.

A good example of how this can be seen in JSON data. In early versions of both platforms, Swift's type security was basically contrary to JSON's formability and its willingness to accept ad hoc features at any time. This led to laborious and superfluous manual code to check, decode and code JSON in early versions of both frames.

Models were particularly painful to design and maintain at this stage. For example, here is a steam 2 model:

  imports steam
import FluentProvider

last class Attachments: Model {

leave storage = storage ()
privately let expirationMinutes =
AppSettings.attachmentExpirationMinutes

struct properties {
static charge key = "key"
static light path = "path"
static expiration = "expires"
}

Item key: String
was path: String
Where expires: Date

init (key: string, path: string) {
self.key = key
self.path = path
self.expires =
Date (). AddTimeInterval (expiration minutes * 60)
}

init (row: row) cast {
key = try row.get (Properties.key)
path = try row.get (Properties.path)
expires = try row.get (Properties.expires)
}

func makeRow () casts -> Row {
was rad = row ()
try row.set (Properties.key, key)
try row.set (Properties.path, path)
try row.set (Properties.expires, expires)
return row
}
}

extension AttachmentsInfo: NodeRepresentable {
func makeNode (in context: Context?) casts -> Node {
var node = node ([ : ] i: context)
try node.set (self.idKey, self.id)
try node.set (Properties.key, key)
try node.set (Properties.path, path)
try node.set (Properties.expires, expires)
Returns hub
}
}

extension AttachmentInfo: Preparation {
static func preparation (_ database: Database) cast {
Try database.create (self) {builder in
builder.id ()
builder.string (Properties.key)
builder.string (Properties.path)
builder.date (Properties.expires)
}
}

static func revert (_ database: Database) cast {
try database.delete (even)
}
}

There are 78 lines of code – and several non-dry methods – for a model with only three simple properties. The corresponding early Kitura code suffers from the same linguistic limitations.

This core problem was addressed in Swift 4 with the Codable protocol, which effectively transformed JSON handling from a debt into an asset through the Swift platform. For their credit, both Kitura and Vapor incorporated aggressively Codable and eliminated the need for turning the verbose code and struck a near perfect balance between Swift's inherent type of security and JSON's flexibility and adaptability. As a result, in Steam 3, the 78-line model above is:

  Import Steam

struct AttachmentInfo: Content, Migration {
leave key: String
la path: String
expires: Date

init (key: string, path: string) {
self.key = key
self.path = path
self.expires =
Date (). AddTimeInterval (AppSettings.attachmentExpirationMinutes * 60)
}
}

Kitura 2's streamlined model is slightly different, but shows almost equal benefits from Codable :

  Import Foundation

struct AttachmentInfo: Codable {
Item key: String
was path: String
Where expires: Date

init (key: string, path: string) {
self.key = key
self.path = path
self.expires =
Date (). AddTimeInterval (AppSettings.attachmentExpirationMinutes * 60)
}
}

This is a great victory and the benefits go well beyond the surface. Both platforms use Codable up and down in stacks, allowing developers to work directly with Swift Structs and Types, while providing full flexibility to capture and output rich JSON data. It's about as good a definition of "best of both worlds" as I know! :]

The benefits of compilation

Server page Swift web apps are statically compiled. This provides several advantages:

  • Compiled web apps are safer in design. There is significantly less exposure and danger if the only assets that are exposed are compiled bit code, rather than human readable source code. This does not give server-side Swift a pass from other security risks, but it is significant.
  • Compiled apps tend to be more performance compared to their transpiled or just-in-time compiled counterparts. A series of benchmarks early on server-side Swift's evolution typically showed the order of magnitude-level performance advantages over common alternatives. For example, the Steam Team presented this platform assembly shortly after the release of Damp 1, which demonstrated impressive performance even in the early stages:

  • But what if you don't need screaming speed? Micro-services and other lightweight components written on a server-side Swift framework are usually expected to be highly effective in their energy and resource use.

    Note : It is unfortunate that there is a remarkable lack of objective references – especially since the platform's earliest evidence date. In my own experience, Damp web apps and services that my team has delivered to corporate customers have been shown to reduce system load 80% – 90% over Node.js-based services they have replaced. Obviously, this is not a substitute for objective benchmarking, which we hope to see soon.

    Lastly, it is important to note that, although Swift on the client side is usually limited to Apple hardware and OS, this limitation does not carry over to Swift on the server. Thanks to the efforts of Apple and the Swift Developer community, server-side Swift can also be deployed on Ubuntu Linux, multiple ship platforms, and almost anywhere using Docker. This is not a competitive advantage but it is worth noting that server-side Swift is on a par with Rails, JavaScript and PHP web apps in this regard.

Differences

Both Vapor and Kitura implement and extend Swift's own advantages in their own specific ways. Each framework has a "taste" with several aspects that make each frame unique.

Heritage

Kitura has been sponsored and controlled by IBM since its inception. Kitura is fully open under the Apache license, but IBM's sponsorship and resources are evident throughout. However, Vapor came to life as an independent framework without company management or sponsorship. Although it picked up its first corporate sponsors shortly afterwards, Damp's independence and developer focus clearly shows his own approach and personality.

Priorities and Philosophy

The effect of these different lines can be seen in various approaches and priorities of the two frameworks that they have developed and responded to Swift's rapid development. Kitura consistently favors predictability and backward compatibility. The API has remained remarkably stable given Swift's own aggressive development over the past few years, and it is a pride for team members that code written in Kitura 1.0 continues to build and go on that day.

Kitura's emphasis on continuity over novelty gives it a slightly conservative feeling. While this may disappoint some developers, it provides continuity and useful tools that are crucial to the business, such as the standard health control route that makes it easy to monitor Kitura web app uptime and performance under load.

On the other hand, Vapor developer-centric roots mean it tends to move more aggressively when new Swift features and technologies are released. Overall, the Steam API has shown significantly more volatility between each version than Kitura, and both Steam 2 and 3 (the current version) have featured deep reworking of both core elements and the exposed API.

This has meant that apps developed in one version usually require significant rewrites to run next. Whether this is a pattern or anti-pattern depends on one's priorities. In the large and highly active steam developer community, these sweeping changes have been generally accepted as the cost of rapid development and improvement.

The same difference is reflected in how the two frames responded to the release of the highly regarded SwiftNIO framework in early 2018. The Vapor core layer integrated it with the earlier upcoming version 3 right away! In an interview with 2018 with Paul Hudson, founder and leading developer Tanner Nelson was revealed that the frames had expected and prepared for this rapid adoption.

Conversely, the Kitura team took a more cautious approach and spent several months testing the NIO and ensuring that the performance margins were fully tested and resolved before it was formally adopted later that year.

Approach to APIs

A similar difference in approach plays out the way the two platforms write and reveal APIs. Steam has been "full stack Swift" right from the start. Whether you are writing route code, interacting with data sources or templating your web pages, you will work in Swift.

The Steam API is built from the ground up to reflect the best methods for writing Swift code. This provides a consistent Swift-y experience across the platform that is likely to appeal strongly to iOS developers who want to expand their Swift expertise to the server. In many cases – for example, with steam's native Swift database drivers – this eliminates the need for non-swift dependencies.

Kitura is approaching APIs from a broader industry perspective, where JavaScript platforms such as Node, Express and Javascript tools are widely used. The Kitura team has chosen to base many APIs, not primarily on Swift standards, but rather on standards from this broader community. For example, the Stencil painting language takes its syntax from the popular Django and mustache tools, and its master syntax is modeled on Express, which is used in a wide variety of Node.js web frames.

This same perspective again shows through Kitura's tendency to use the best available tools for a given task, regardless of language. This would be an anti-pattern in the Damp community, where all the core elements are implemented in Swift. But there is wisdom in Kitura's approach, which is evident from a business perspective. And experienced web developers are likely to appreciate an approach that allows them to take advantage of Swift's best features while utilizing conventions and tools they've already mastered elsewhere.

Take a look at the implementation style in both frames. [19659008] Programming style

Once again, Vapor is more aggressively Swift-y and first-class than Kitura, here.

In the current version 3, the Vapor syntax contains powerful use of lifting-like Futures as a core of the version's async performance optimizations and its inclusion of SwiftNIO . This makes Steam Code more openly functional in style, with extensive use of nested closures and function-oriented methods such as map () and flatMap () in evidence everywhere.

This tends to give Vapor a characteristic abstract flavor, as the code is almost universally about manipulating, waiting, and reasoning about async futures that may or may not be fulfilled in real time. For example, there is a simple steam route:

  func getAllHandler (_ req: Request) throws -> Future <[User]> {
return User.query (on: req) .all ()
}

Here is a more complex route that combines async and functional features:

  func userHandler (_ req: Request) casts -> Future  {
return try req.parameters.next (User.self)
.flatMap (to: View.self) {uses in
return sample user.acronyms
.query (on: req)
.everyone()
.flatMap (for: View.self) {acronyms in
la context = UserContext (title: username, user: user, acronyms: acronyms)
return sample req.view (). render ("user", context)
}
}
}

In contrast, although Kitura also utilizes NIO and async, it exposes less in the API. As a result, Kitura coding – and routing in particular – tends to look more "concrete" than Vapor.

For example, here is a test route in Kitura:

  func getEntries (user: UserAuth,
query: JournalEntryParams?,
completion: @escaping ([JournalEntry] ?, RequestError?) -> Feid) {
JournalEntry.findAll (matching: query, for: user, completion)
}

Performance

How do the two frames compare in performance? Unfortunately, as we have already seen, this question cannot be objectively answered at this time, as there is no standardized set of references we can apply for the two frames and the best goals we have come from the early days of both platforms.

Both frameworks have evolved sharply since these early days – invest heavily in core window optimizations – and the community's consensus is that the previously documented benefits have only increased over time.

When we compare Kitura and Damp head to head, we know that both framework conditions take great advantage of Swift's most prestigious aspects, and that both have made excellent use of modern tools such as SwiftNIO. But beyond that, there is little, if any, objective empirical evidence to prefer one over the other: Both have been extensively matched, with very positive subjective reports from the field. But keep an eye on this room … there's a good chance you'll see new sets of references in the near future!

What is it like to implement an app with these frames?

Implementation and Distribution

One of the really nice things about Kitura's broader industry focus is that it embraced Docker implementations very early. This decision has again provided stability and continuity across Kitura versions. And that means it has long been possible to implement Kitura solutions wherever Docker extends.

The steam society was basically less enthusiastic about Docker as a distribution target, but with Damp 3, Docker implementations have become much more common. At this point, both platforms are largely in line with this, and it seems clear that streamlining the Docker distribution will be central to future development of both platforms.

Extensibility

We have focused mostly on internals so far. Another great consideration when choosing a web frame is its width and extensibility. How easy can you add new integrations and capabilities to it when your project grows?

Kitura benefits from a strong library of packages. Currently there are over 50 IBM supported packages. For its part, Vapor provides a wide range of community resources, which currently count over 100.

In both contexts, both frames have done a lot on this front in a short time, and neither is it nearer (yet) to achieve the Width and the richness of available packages that competing frames have evolved over time. For some metric, this is currently a growth problem experienced by the entire server-side Swift community.

Practically, if you want to do something outside the current crop of official Kitura packages or Vapor Community frames, it's likely that you have to do some bushwhacking on your own. Depending on the specific problem, the solution of a case like this may mean adapting an existing open source framework or having to implement a new feature from scratch.

Damp and Kitura are members of SSWG that help steer direction on an initiative to enable future packages. This means that the new packages built on top of NIO and the following common conventions will soon work with both Damp and Kitura. This, in turn, has the potential to transform the expansion landscape across the server-side Swift landscape very much for the better in the near future.

Which one should you choose?

It is probably clear that choosing which framework is right for you will determine which one fits your own code style and the needs of a particular project.

Here is an overview of the most important comparisons between these two major frames:

  • What is most important to you? Stable, backward compatible API or early adoption of new Swift technologies as soon as possible after they appear? If you need to ensure that the code you write today will remain unchanged for as long as possible, Kitura can appeal to you more. If you prioritize maximizing fresh Swift goodness and can accept the cost of potentially significant break changes between releases, Vapor is your likely choice.
  • Do you prefer tools and APIs drawn from the broader web business, or would you prefer them to maximize Swift sensibilities? If you come from a Rails / JavaScript / PHP perspective and generally like the tools you have used, Kitura will probably appeal the most. If you come from IOS and native Apple development and don't have a heavy investment in the JavaScript API, the Vapor approach will probably call you. The same dynamics continue as we consider the technical stacks in each framework. If you know and like regular web tools, you'll probably be happy to have non-swift, industry-standard tools and grammars in your tech stack. Swift purists and iOS developers without deep network utility investments will probably prefer a clean Swift stack at the top of the bottom.
  • What about API style? If you are a fan of functional programming and are comfortable with their abstractions, Vapor will probably appeal strongly. On the other hand, Kitura's more traditional approach can be a better match if you prefer your code to be less abstract and no doubt easier to get your head on.
  • How and where do you want to distribute your web apps? The difference between the two is less pronounced here than it has been in the past, but differences in weight and support remain. If you have an investment in IBM's cloud offer, Kitura is a clear winner. The Vapor Cloud platform has several attractive features, but is still relatively young, while some tough edges remain. Beyond that, both platforms provide ever-increasing support to Docker and, by extension, almost all major ship platforms.
  • How's the performance? In a word, amazing. Both frames provide very good performance and efficiency on a scale. Generally, if efficiency or performance are important considerations, this is a potentially strong reason to select either of these server-side Swift frames over other industrial competitors. At this point, there are just no strong reasons to choose between Kitura and Vapor on this basis.
  • How much functionality will you build from scratch? We have seen that both Damp and Kitura have relatively strong sets of third parties and extended frames available in their respective ecosystems. But it also doesn't come close to what's available for more mature JavaScript, Ruby, PHP and other frames. If you want to add a lot of functionality outside the box to what the platform supports, this is a likely indicator that the project you are considering is not (yet) a good candidate for the Server side Swift.
    • Summary

      There is no obvious winner. And at the end of the day, that's a nice thing. We should appreciate that the Swift community is deep and robust enough to support multiple thriving server-side platforms, each with its distinct approach and benefits. It is also worth appreciating that both platforms give back to the community by actively contributing to the ongoing development of Swift itself.

      Technically, it's simply no wrong choice. If you want to dive into server-side Swift, you should take the chance! The water is just fine, and both the steam and Kitura ends of the pool are great places to swim.

      Finally, the choice comes down to your own priorities, needs and style. I would strongly urge you to play with both platforms and decide for yourself. Take a closer look at the resources available on the Vapor and Kitura areas. I also encourage you to consider our Kitura and steam books as well as our complete Vapor and Kitura web courses. You can't go wrong with either. :]

      If you have any questions or comments, join the forum discussion below!)


Source link