Skip to content

Commit c716814

Browse files
Update all Vapor examples to use async execute() API (#451)
### Motivation Recently Vapor introduced the `execute() async` API for running the server to replace the blocking `run()`. We should make an effort to use this better API in our examples that use Vapor. ### Modifications Update all Vapor examples to use Vapor 4.89.0+ and async execute() API. ### Result All Vapor examples use async execute() API. ### Test Plan CI.
1 parent 601f9f4 commit c716814

File tree

26 files changed

+38
-38
lines changed

26 files changed

+38
-38
lines changed

Examples/AuthenticationServerMiddleware/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ let package = Package(
2121
.package(url: "https://github.com/apple/swift-openapi-generator", exact: "1.0.0-alpha.1"),
2222
.package(url: "https://github.com/apple/swift-openapi-runtime", exact: "1.0.0-alpha.1"),
2323
.package(url: "https://github.com/swift-server/swift-openapi-vapor", exact: "1.0.0-alpha.1"),
24-
.package(url: "https://github.com/vapor/vapor", from: "4.87.1"),
24+
.package(url: "https://github.com/vapor/vapor", from: "4.89.0"),
2525
],
2626
targets: [
2727
.target(

Examples/AuthenticationServerMiddleware/Sources/HelloWorldVaporServer/HelloWorldVaporServer.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct Handler: APIProtocol {
3131
}
3232

3333
@main struct HelloWorldVaporServer {
34-
static func main() throws {
34+
static func main() async throws {
3535
let app = Vapor.Application()
3636
let transport = VaporTransport(routesBuilder: app)
3737
let handler = Handler()
@@ -58,6 +58,6 @@ struct Handler: APIProtocol {
5858
})
5959
]
6060
)
61-
try app.run()
61+
try await app.execute()
6262
}
6363
}

Examples/ContentTypesServer/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ let package = Package(
2121
.package(url: "https://github.com/apple/swift-openapi-generator", exact: "1.0.0-alpha.1"),
2222
.package(url: "https://github.com/apple/swift-openapi-runtime", exact: "1.0.0-alpha.1"),
2323
.package(url: "https://github.com/swift-server/swift-openapi-vapor", exact: "1.0.0-alpha.1"),
24-
.package(url: "https://github.com/vapor/vapor", from: "4.87.1"),
24+
.package(url: "https://github.com/vapor/vapor", from: "4.89.0"),
2525
],
2626
targets: [
2727
.executableTarget(

Examples/ContentTypesServer/Sources/ContentTypesServer/ContentTypesServer.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,11 @@ struct Handler: APIProtocol {
158158
}
159159

160160
@main struct ContentTypesServer {
161-
static func main() throws {
161+
static func main() async throws {
162162
let app = Vapor.Application()
163163
let transport = VaporTransport(routesBuilder: app)
164164
let handler = Handler()
165165
try handler.registerHandlers(on: transport, serverURL: URL(string: "/api")!)
166-
try app.run()
166+
try await app.execute()
167167
}
168168
}

Examples/GreetingService/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ let package = Package(
2121
.package(url: "https://github.com/apple/swift-openapi-generator", exact: "1.0.0-alpha.1"),
2222
.package(url: "https://github.com/apple/swift-openapi-runtime", exact: "1.0.0-alpha.1"),
2323
.package(url: "https://github.com/swift-server/swift-openapi-vapor", exact: "1.0.0-alpha.1"),
24-
.package(url: "https://github.com/vapor/vapor", from: "4.76.0"),
24+
.package(url: "https://github.com/vapor/vapor", from: "4.89.0"),
2525
],
2626
targets: [
2727
.executableTarget(

Examples/GreetingService/Sources/GreetingService/GreetingService.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct Handler: APIProtocol {
4141
/// }
4242
/// ```
4343
/// - Throws: An error of type `Error` if there's an issue creating or running the Vapor application.
44-
public static func main() throws {
44+
public static func main() async throws {
4545
// Create a Vapor application.
4646
let app = Vapor.Application()
4747

@@ -55,6 +55,6 @@ struct Handler: APIProtocol {
5555
try handler.registerHandlers(on: transport, serverURL: Servers.server2())
5656

5757
// Start the Vapor application, in the same way as if it was manually configured.
58-
try app.run()
58+
try await app.execute()
5959
}
6060
}

Examples/HelloWorldVaporServer/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ let package = Package(
2121
.package(url: "https://github.com/apple/swift-openapi-generator", exact: "1.0.0-alpha.1"),
2222
.package(url: "https://github.com/apple/swift-openapi-runtime", exact: "1.0.0-alpha.1"),
2323
.package(url: "https://github.com/swift-server/swift-openapi-vapor", exact: "1.0.0-alpha.1"),
24-
.package(url: "https://github.com/vapor/vapor", from: "4.87.1"),
24+
.package(url: "https://github.com/vapor/vapor", from: "4.89.0"),
2525
],
2626
targets: [
2727
.executableTarget(

Examples/HelloWorldVaporServer/Sources/HelloWorldVaporServer/HelloWorldVaporServer.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ struct Handler: APIProtocol {
2323
}
2424

2525
@main struct HelloWorldVaporServer {
26-
static func main() throws {
26+
static func main() async throws {
2727
let app = Vapor.Application()
2828
let transport = VaporTransport(routesBuilder: app)
2929
let handler = Handler()
3030
try handler.registerHandlers(on: transport, serverURL: URL(string: "/api")!)
31-
try app.run()
31+
try await app.execute()
3232
}
3333
}

Examples/MetricsMiddleware/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ let package = Package(
2121
.package(url: "https://github.com/apple/swift-openapi-generator", exact: "1.0.0-alpha.1"),
2222
.package(url: "https://github.com/apple/swift-openapi-runtime", exact: "1.0.0-alpha.1"),
2323
.package(url: "https://github.com/swift-server/swift-openapi-vapor", exact: "1.0.0-alpha.1"),
24-
.package(url: "https://github.com/vapor/vapor", from: "4.87.1"),
24+
.package(url: "https://github.com/vapor/vapor", from: "4.89.0"),
2525
.package(url: "https://github.com/apple/swift-metrics", from: "2.4.1"),
2626
.package(url: "https://github.com/swift-server/swift-prometheus", exact: "2.0.0-alpha.1"),
2727
],

Examples/MetricsMiddleware/Sources/HelloWorldVaporServer/HelloWorldVaporServer.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ struct Handler: APIProtocol {
2626
}
2727

2828
@main struct HelloWorldVaporServer {
29-
static func main() throws {
29+
static func main() async throws {
3030
let registry = PrometheusCollectorRegistry()
3131
MetricsSystem.bootstrap(PrometheusMetricsFactory(registry: registry))
3232

@@ -50,6 +50,6 @@ struct Handler: APIProtocol {
5050
let host = ProcessInfo.processInfo.environment["HOST"] ?? "localhost"
5151
let port = ProcessInfo.processInfo.environment["PORT"].flatMap(Int.init) ?? 8080
5252
app.http.server.configuration.address = .hostname(host, port: port)
53-
try app.run()
53+
try await app.execute()
5454
}
5555
}

0 commit comments

Comments
 (0)