Can you use Swift as a web programming language? [closed]
Could you technically use Swift as a programming language for building a website / web app?
Update: Looks like a lot of people are working on this.
- https://github.com/PerfectlySoft/Perfect
- https://github.com/glock45/swifter
- https://github.com/grzegorzleszek/HTTPSwiftServer
- https://github.com/izqui/Taylor
- https://github.com/crossroadlabs/express
- https://github.com/IBM-Swift/Kitura
- https://github.com/vapor/vapor
Official support from Apple: https://swift.org/server-apis/
Solution 1:
In theory, of course.
Any program that can output plain text can also be used for CGI(Common Gateway Interface) which includes Swift as well.
Therefore, yes, you can use Swift for web programming. However, currently, there are no additional libraries(like there are in PHP or EJB/JSP) to make this process easy for you. Take a look at some popular web frameworks for Swift such as Vapor.
Solution 2:
Not sure how active this topic is anymore, but in case anyone finds this in the future, I'd like to announce here that I have started working on a framework for writing FastCGI applications in Swift.
Of course you can use any Objective-C web framework (though there are rather few), and you can certainly use Swift as a scripting language to dump out HTML strings to be regurgitated by CGI. However, (I'm going to get all philosophical here) I think that settling for such an approach is not very "Swift-like" if I dare use the term. The Swift designers went through a lot of trouble to make sure that it's more than "just" Obj-C without the (constraints of) C (in fact, I almost wish they hadn't said that since it's so often misquoted). Swift is also much closer to the functional family than Obj-C (while still retaining solid object orientation AND managing to add Python-esque scriptability). This opens up a whole new world of design choices that I think need to be explored. Also, type safety... but I digress...
All this to say, I've taken it upon myself to create a modular "microframework" that will let you write web apps in Swift at a very high level. At the time of this writing, I'd classify it as a functional proof of concept, but it's still not as abstract as I'd like and is missing a number of key features that would be necessary for real-world use. Contributions are of course welcome. Hope somebody finds this helpful. https://github.com/ianthetechie/SwiftCGI