Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Very basic HTTP implementation in Swift (github.com/huytd)
45 points by huydotnet on Dec 4, 2015 | hide | past | favorite | 24 comments


Sorry - 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.


But, 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.


I 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.


Here's a full blown application server as well. https://github.com/PerfectlySoft/Perfect


There is full http server: https://github.com/glock45/swifter


Swift 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.


In that sense, would you be comparing Swift to Go, Python/Ruby, JavaScript, PHP? Is Swift "better" than the others?


Swift 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.


Why is two thirds of the README dedicated to Docker? must everything be a Docker container now?


Basically, you can install Swift directly on your Linux machine, but for Mac users who not using El Capitan or Windows users, they will need Docker


Unrelated, but is this a common practice in Swift?

    #if os(Linux)
        import Glibc
    #else
        import Darwin.C
    #endif
Feels a bit nasty.


AFAIK, 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/


Yeah, I grabbed this lines from Apple document https://swift.org/package-manager/#example-usage


Are a bunch of #ifdef's in C any less nasty?


I would imagine it to be a fact of life for library developers.


Interesting 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?


I made something in the Swift 1.0 days called "swell" that shows how this might look.

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.


Yeah 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


Here's one. 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.


I 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.


Aeon is an HTTP server written in Swift that has an API that looks like Sinatra. https://github.com/Zewo/Aeon


How mature is Swift for writing backend applications in its current state when compared to Python or maybe Rust ?


It's potential :D


Oh, this is so cute...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: