Vapor: a type-safe web framework for Swift
github.com
github.com
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.
Been looking into this recently so leaving it here as friendly competition: https://air.mozilla.org/ur-web-a-simple-model-for-programmin...
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.
Can you explain?
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.
I'd say a language is general-purpose when it has not been tailored to a specific scenario or area of problems, but to work well for most. Isn't that, to a great extent, true for go?
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.
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=...
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.
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.
Also, yes, I think concurrency model in node.js is the worst possible one.
https://github.com/tannernelson/vapor/blob/master/Sources/So...
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.
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.
Once Fluent supports MySQL, I'll definitely use Vapor in a project.
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.
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.
If you like Ruby on Rails you will like Swifton for Swift https://github.com/necolt/Swifton .
Check out Frank (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.Aside from perfect.org there's
- https://github.com/glock45/swifter
- https://github.com/grzegorzleszek/HTTPSwiftServer
- https://github.com/izqui/Taylor
- https://github.com/crossroadlabs/express
...and even mor here 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
If I could think of a name, I'd release it right now just to add it to your sweet list.
A user should be free to choose their favourite web framework and then choose the best web server for their needs.
https://github.com/necolt/swifton (A Ruby on Rails inspired Web Framework for Swift that runs on Linux and OS X)