9 ms·
Vapor: a type-safe web framework for Swift
- siquick 11y agoThis looks excellent and reminds me of the simplicity of Flask. Once Fluent supports MySQL, I'll definitely use Vapor in a project.
- cm3 11y agoGood to see people getting serious about Swift cross platform projects. Let's hope it doesn't share the fate of Apple's Dylan projects. Been looking into this recently so leaving it here as friendly competition: https://air.mozilla.org/ur-web-a-simple-model-for-programming-the-web/ https://air.mozilla.org/ur-web-a-simple-model-for-programmin...
- melling 11y agoWhy would you compare it to Dylan? Swift will be the most popular iOS language within 18 months. If you look at the new iOS books that are released, most use Swift. I count over 3 dozen books within 18 months of Swift's release: http://www.h4labs.com/dev/ios/books http://www.h4labs.com/dev/ios/books
- deleted 11y ago[deleted]
- cies 11y agoI also really have great hopes for Swift as a modern, x-platform, general purpose, compiled language. Go is not general purpose; Rust is too low level. Haskell has a too steep learning curve. Ur/Web is really great, but not at all general purpose. Why am I hung up over "general purposeness"? Well when I learn a language, it takes quite a bit of my time; then I want to be able to apply it broadly. Therefor I shun Node.js, Go and Erlang/Elixir.
- cm3 11y agoUr/Web is for web and thus not general purpose. I can't say if Ur (without web) is fit for general purpose use.
- mayhew 11y ago> Go is not general purpose Can you explain?
- wantreprenr007 11y agoThere is no arguing with Turing equivalence of Go and most other languages but there are practical limitations which prevent more complete general purposeness. I like Go since the beginning. However, Go cannot be easily used for kernel development, soft or hard real-time or embedded systems (no linker script support and porting runtime is weighty) and there are few transpilers. Rust is slightly better, because PoC kernels have been put together with fewer hacks. Haskell, C, Ada, assembly are much more general purpose in terms of being able to build something like seL4, an F-15 cockpit, an engine management system or compiling code as ASIC circuitry. (Perl's supposed use in nuclear armaments notwithstanding.) PS: I would like to see some geninuses come up with a back-back-end to LLVM or a disassembler which could formally prove binary satisfiability of program correctness without mind-bending, gibberish, over-mathematized, incantations inaccessible to us mere, stupid mortals.
- absker 11y agoHow is Go not general purpose?
- tcdent 11y agoThe JSON response trick is just the right amount of magic. I'm eager to make Swift my new web dev language and this looks like a very promising option if they continue to maintain that balance.
- hocuspocus 11y agoHonest question: what's the appeal of Swift outside of iOS/OSX development? I can understand the need for an Objective-C replacement, but after more than two decades of evolution, web dev doesn't lack of good and modern languages running on top of very performant and mature platforms, with rich ecosystems. Swift brings absolutely nothing to the table.
- cthulha 11y agoTurn that around: lets say you know Swift because you're an iOS developer. What web dev languages or platforms can you use? The same argument was made about Node.JS, that backend services already had great languages / platforms / ecosystems. It's not about existing experts in the area learning a new stack, it's about enabling experts in one domain to reach 'good enough' in another rapidly.
- jacobwcarlson 11y agoIs there documentation I'm missing? Based just on the readme I don't think I understand how this works. For instance, the section on the Request object omits HTTP headers, then the Async section shows sending response headers manually. But they're sent asynchronously for some reason? There's a .Hash method that apparently does SHA-1 hashing, though I don't know why. At the point I stopped reading because I didn't understand what the examples were telling me. I don't mean to be negative or try to poke holes in your hard work. I'd just like to know how to use it. "Insanely fast, beautiful syntax, type safe" are super alluring features! But let me know how I can build a real application with it.
- tannernelson 11y agoThere is additional documentation in the Wiki.
- deleted 11y ago[deleted]
- squidbidness 11y agoI'll admit my total naivete up front: isn't Swift already a typed language? Is there something about being a web framework that necessitates some other kind of type safety?
- zoul 11y agoThe more advanced a type system is, the more it depends on what you do with it when designing an API. A well designed API in a language with a rich, expressive type system can make higher-level guarantees. On the opposite side of the spectrum you could just use Strings for most of the types (it’s web after all!) and it would still be type safe, although the type guarantees wouldn’t be of much use.
- kylef 11y agoYes, this framework in particular doesn't demonstrate the benefits and uses of the type-safety and compile-time safety in Swift. Check out Frank (https://github.com/nestproject/Frank#routes https://github.com/nestproject/Frank#routes) which offers type-safe and compile-time safe path routing. You define a closure to handle requests matching paths with type-safety. You are passed the correct parameter types and the correct amount of parameters directly to your closure. This gives you compile type safety. // Handle GET requests to path /users/{username} get("users", *) { (request, username: String) in return "Hello \(username)" } In contrast, without this compile-time safety you will most likely be passed an array of Strings and you will have to pull items out. Route.get("users/:username") { request in if let username = request.parameters["username"] { // Return something with username } else { // TODO Return 404 } } Here you have to manually validate these parameters, there is also the lack of compile time safety in the way you are writing a hard-coded string for each parameters. There is a string "username" twice, both the path and when you pull out the parameter from the array. There is a large room for user error or typos here.
- squidbidness 11y agoThanks for the clarifications. As soon as web text-based protocols were mentioned, I said "oh duh" to myself. There's nothing about the availability of a type system that forces a plain-data wrapper library to use it.
- harryf 11y agoOh dear. Already a 2nd web framework in Swift. Are we about to have a cambrian explosion of Swift web frameworks, ensuring obscurity for all?
- jaxondu 11y agoThis is a new one: https://github.com/necolt/swifton https://github.com/necolt/swifton (A Ruby on Rails inspired Web Framework for Swift that runs on Linux and OS X)
- ascorbic 11y agoCompetition is good. Two frameworks doesn't mean there'll be an explosion.
- harryf 11y agoSo took a look and turns out already happening... Aside from perfect.org there's - https://tailorframe.work https://tailorframe.work - https://github.com/glock45/swifter https://github.com/glock45/swifter - https://github.com/grzegorzleszek/HTTPSwiftServer https://github.com/grzegorzleszek/HTTPSwiftServer - https://github.com/izqui/Taylor https://github.com/izqui/Taylor - https://github.com/crossroadlabs/express https://github.com/crossroadlabs/express ...and even mor here https://github.com/search?utf8=&q=web+framework+language%3ASwift&type=Repositories&ref=advsearch&l=Swift&l= https://github.com/search?utf8=&q=web+framework+language%3AS... > Competition is good ... except when it isn't. JavaScript fatigue... https://news.ycombinator.com/item?id=10796567 https://news.ycombinator.com/item?id=10796567
- sehr 11y agoJavaScript is a bit of a "special" example.
- danappelxx 11y agoInteresting you mention so many similar HTTP servers but not Zewo (https://github.com/Zewo https://github.com/Zewo)
- deleted 11y ago[deleted]
- Raed667 11y agoWhat's the best GUI IDE for a new comer to swift?
- marvel_boy 11y agoXcode or AppCode(from JetBrains).
- Raed667 11y agoBoth run only on mac if I remember well? Anything that could run on ubuntu?
- wavesplash 11y agoAll the Jetbrains IDEs are cross platform (Linux too)
- antfarm 11y agoAtom https://atom.io/ https://atom.io/ https://medium.com/@Aciid/hacking-atom-to-create-a-swift-ide-that-runs-on-linux-and-mac-c7d9520a0fac#.b961hm86h https://medium.com/@Aciid/hacking-atom-to-create-a-swift-ide...
- fit2rule 11y agoI've been using vim + vim-swift (https://github.com/keith/swift.vim https://github.com/keith/swift.vim) to learn Swift, with great results ..
- 11y ago
- hellofunk 11y agoReminds me of Clojure's Compojure library
- deleted 11y ago[deleted]
- mpweiher 11y agoHow is this "insanely fast"? Running an example main with the route '/' mapped to return "Hello World" ab -n 10000 http://127.0.0.1:8080/ I get 1400 requests/s in debug mode and 1900 requests/s in release mode. With wrk, I actually get between 3000-4000 requests/s with default parameters. Most of the time. Sometimes it just hangs. Trying to increase the number of requests with the -r parameter made the hangs consistent, I was not able to get wrk to finish in more than a dozen attempts, so there appears to be a problem with it dying under load. For comparison, the built-in Apache gets 15000-20000 requests/s, my own web-framework based on libmicrohttpd + an Objective-C/Objective-Smalltalk wrapper gets around 25000-32000. None of these would be classified as "insanely" fast, and they are around an order of magnitude faster than this. It's actually a lot closer to Ruby/Sinatra (~600 requests/s). EDIT: project readme says "insanely", not "blazingly", so updated.
- geocar 11y agoIt is perhaps not the definition of "insane" that you are looking for.
- boomlinde 11y agoIf so, one that ignores the performance of the alternatives.
- endymi0n 11y agoAt least the insanely fast speed of Vapor also goes well on the client side with Vapor.JS, the world's smallest and fastest JavaScript library: https://github.com/madrobby/vapor.js/tree/master https://github.com/madrobby/vapor.js/tree/master
- TazeTSchnitzel 11y agoI prefer VanillaJS: http://vanilla-js.com/ http://vanilla-js.com/
- tannernelson 11y ago"insanely" fast was meant as a comparison to languages like PHP and means both performance and time it takes to set up.
- eddd 11y agoBut why? Why would you create a web framework in a single-thread environment? This line of code: https://github.com/tannernelson/vapor/blob/master/Sources/Server.swift#L136 https://github.com/tannernelson/vapor/blob/master/Sources/Se... - makes this framework totally useless.
- goldenkey 11y agoDo you realize that node.js is single threaded? Having more than one process works fine for most purposes. Because the bottlenecks are more IO driven than CPU time.
- eddd 11y agoPlease check the function I am referring to. Also, yes, I think concurrency model in node.js is the worst possible one.
- gilgoomesh 11y agoThe server isn't single threaded. It uses the dispatch concurrent thread pool for processing. The (granted, ugly) line you've linked is for blocking and keeping the main thread alive so the process doesn't end. However, the requests are processed on the dispatch "Background" queue. See "boot" here: https://github.com/tannernelson/vapor/blob/master/Sources/SocketServer.swift#L21 https://github.com/tannernelson/vapor/blob/master/Sources/So...
- cellularmitosis 11y ago
- Ciantic 11y agoI suppose most who do Swift at the moment also use it on front-end, since this advertises being "type-safe" what is their preferred method to connect to this JSON server from the Swift front-end in type safe manner? Also, the Fluent is clearly not type-safe, it's stringly typed ORM to database. Since many backends are just fancy wrappers to database, this part should be most important for type-safety. It's nowhere as type safe as Quill, Slick or JOOQ.
- w4 11y ago> I suppose most who do Swift at the moment also use it on front-end Given that it's primarily used for iOS and Mac OS X programming, yeah, of course. Both the GUI and app logic are typically coded in Swift.
- wereHamster 11y agoIt's weird how little qualifies for 'type-safe' nowadays. The templating language is not typesafe for example. The parameters in the request aren't either. Take a look at http://haskell-servant.github.io/ http://haskell-servant.github.io/ if you want to see what type-safe means.
- twic 11y agoIndeed, i don't see anything about it that's particularly type-safe, and the claim is not discussed beyond the bullet point at the top.
- tannernelson 11y agoWe are working hard to make all aspects of Vapor totally type safe. But, just by merit of being Swift, it's already infinitely more type safe than something like PHP. A key goal of the project is to avoid the use of `Any` anywhere possible, and to move any run time safety checks to compile time.
- xaduha 11y agoAlmost anything is better than PHP, that doesn't make this particular framework standout among many tens of others. In any case, I'm not going to consider using any framework that isn't on the first half of this list https://www.techempower.com/benchmarks/#section=data-r11&hw=peak&test=json https://www.techempower.com/benchmarks/#section=data-r11&hw=... Many of them are for JVM, but one cool thing about JVM, is that you don't have to use Java (Kotlin is often compared to Swift for example) while still using frameworks written in Java, like Undertow or Rapidoid.
- necolt 11y agoFrameworks. Frameworks Everywhere. If you like Ruby on Rails you will like Swifton for Swift https://github.com/necolt/Swifton https://github.com/necolt/Swifton .