Hello everyone,
We'd like to pitch the main Vapor package to the SSWG incubation process. Vapor is one of the oldest and biggest server-side Swift frameworks used by many companies big and small.
Motivation
Server-side Swift frameworks provide the tools to allow developers to write backends, APIs and server-applications in Swift without application developers needing to know all of the internals of interacting with the kernal, parsing HTTP packets, managing routing, handling request and response bodies or even interacting with SwiftNIO. This allows developers to focus on their business logic.
Proposed Solution
Vapor has been around since 2016, with Vapor 4 being the current version for the last 4 years. It's evolved over the years and currently supports async
/await
and compiles with no warnings with strict concurrency checking in Swift 5.9 (a few warnings in 5.10 which will be fixed very soon).
Vapor supports parameter based routing and route handlers as closures (or functions):
app.get("hello", "vapor") { req in
return "Hello, vapor!"
}
Dynamic path parameters are also supported:
app.get("hello", ":name") { req -> String in
let name = req.parameters.get("name")!
return "Hello, \(name)!"
}
Vapor also supports Codable based types for request and response bodies:
struct Greeting: Content {
var hello: String
}
app.post("greeting") { req in
let greeting = try req.content.decode(Greeting.self)
print(greeting.hello) // "world"
return HTTPStatus.ok
}
This could then handle the following request:
POST /greeting HTTP/1.1
content-type: application/json
content-length: 18
{"hello": "world"}
Vapor also supports middleware, authentication, websockets, validation, external HTTP requests, testing, and many more features. See Vapor's documentation for the full features and documentation and our API docs.