8 ms·
Very basic HTTP implementation in Swift
- cdnsteve 11y agoI think this opens up the possibilities for Swift to be used as a web language, not just a iOS language. I have to say, Swift syntax is very similar to PHP 7. Interesting times for sure. I'll be keeping a close eye on Swift in terms of its adoption as a web language.
- EugeneOZ 11y agoThere is full http server: https://github.com/glock45/swifter https://github.com/glock45/swifter
- hundchenkatze 11y agoHere's a full blown application server as well. https://github.com/PerfectlySoft/Perfect https://github.com/PerfectlySoft/Perfect
- pbreit 11y agoIn that sense, would you be comparing Swift to Go, Python/Ruby, JavaScript, PHP? Is Swift "better" than the others?
- cballard 11y agoSwift has a passable type system, support for generics, and doesn't use a VM. Tooling support isn't there for Linux currently, so the act of writing code isn't much better than Python (no Xcode-type autocompletion), but once you want to run it, the compiler will scream at you if you pass ducks where penguins are expected - while still allowing you to reason about swimming birds in general.
- EugeneOZ 11y agoSwift has nothing similar to PHP 7. Typing in PHP 7 is ridiculous - you can set "Array" as a "strict" type of return value, but inside that array you can have whole universe. And any optional type system is not a type system at all. I learned it when tried Dart. PHP 7 is too primitive in comparison with Swift.
- andoma 11y agoOh, this is so cute...
- nodesocket 11y agoInteresting to see if an Express like framework comes about. Does it even make sense to write a backend http RESTful API in Swift? Wonder what the performance is vs node.js and go?
- huydotnet 11y agoYeah that's what I'm planning to do, I have the previous express-like framework in C++ and now I'm porting it to Swift :D
- breckinloggins 11y agoI made something in the Swift 1.0 days called "swell" that shows how this might look. https://github.com/breckinloggins/Swell https://github.com/breckinloggins/Swell It could be used as an example. In particular, the "builder" syntax that I did with a terrible TLS context hack could be replaced with autoclosures (I think). Edit: more Sinatra-like than Express-like, but the idea still stands.
- hundchenkatze 11y agoHere's one. https://github.com/PerfectlySoft/Perfect https://github.com/PerfectlySoft/Perfect Since work was started on this before Swift's open sourcing/linux support was added I doubt it compiles on linux just yet. I'm sure it'll be added though.
- nodesocket 11y agoUnrelated, but is this a common practice in Swift? #if os(Linux) import Glibc #else import Darwin.C #endif Feels a bit nasty.
- huydotnet 11y agoYeah, I grabbed this lines from Apple document https://swift.org/package-manager/#example-usage https://swift.org/package-manager/#example-usage
- trymas 11y agoAFAIK, at least for now it is. Libraries on Linux and OS X just are different. Maybe when core libraries [0] will be fully finished we could just use `import Foundation` on both platforms. [0] https://swift.org/core-libraries/ https://swift.org/core-libraries/
- nly 11y agoAre a bunch of #ifdef's in C any less nasty?
- edgyswingset 11y agoI would imagine it to be a fact of life for library developers.
- srameshc 11y agoHow mature is Swift for writing backend applications in its current state when compared to Python or maybe Rust ?
- huydotnet 11y agoIt's potential :D
- Matthias247 11y agoSorry - but sending a bunch of static bytes through a TCP socket without even reading something from the input is not even a basic HTTP implementation.
- mpweiher 11y agoBut, but, but...it's in Swift!!!! It is therefore already vastly superior to any and all full web server and application server solutions and defines how servers will be written in the future. Particularly, all the web server solutions written in Objective-C have ceased to exist.
- Wonnk13 11y agoWhy is two thirds of the README dedicated to Docker? must everything be a Docker container now?
- pkaler 11y agoAeon is an HTTP server written in Swift that has an API that looks like Sinatra. https://github.com/Zewo/Aeon https://github.com/Zewo/Aeon
- EugeneOZ 11y agoI don't think Swift is a very good choice for the web - we already have much better options. Swift compiler don't care about memory leaks, runtime errors and race conditions. And it's really easy to get runtime error - just unwrap optional value without check. So I think Swift is good for something what can run few minutes and be restarted easily in case of failure - mobile and desktop apps. Not web server daemons.