Skip to content

Commit a393d2b

Browse files
authored
Examples: Add a Hello World example using Hummingbird (#3)
### Motivation Having simple "getting started" examples is helpful for new users. Some users may be more familiar with Hummingbird instead of Vapor. ### Modifications Adds another example, using Hummingbird, and links it into the documentation. ### Result New users who want to use Hummingbird can start from a tested starting point. ### Test Plan Built and deployed the example locally, and ran the soundness checks.
1 parent 3383c16 commit a393d2b

File tree

6 files changed

+274
-1
lines changed

6 files changed

+274
-1
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.DS_Store
2+
/.build
3+
/Packages
4+
xcuserdata/
5+
DerivedData/
6+
.swiftpm/configuration/registries.json
7+
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
8+
.netrc

Examples/HelloWorldHummingbird/Package.resolved

Lines changed: 204 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// swift-tools-version: 6.0
2+
3+
//===----------------------------------------------------------------------===//
4+
//
5+
// This source file is part of the SwiftContainerPlugin open source project
6+
//
7+
// Copyright (c) 2024 Apple Inc. and the SwiftContainerPlugin project authors
8+
// Licensed under Apache License v2.0
9+
//
10+
// See LICENSE.txt for license information
11+
// See CONTRIBUTORS.txt for the list of SwiftContainerPlugin project authors
12+
//
13+
// SPDX-License-Identifier: Apache-2.0
14+
//
15+
//===----------------------------------------------------------------------===//
16+
17+
import PackageDescription
18+
19+
let package = Package(
20+
name: "hello-world",
21+
platforms: [.macOS(.v14)],
22+
dependencies: [
23+
.package(url: "https://github.com/hummingbird-project/hummingbird.git", from: "2.1.0"),
24+
.package(url: "https://github.com/apple/swift-container-plugin", from: "0.1.0"),
25+
],
26+
targets: [
27+
.executableTarget(name: "hello-world", dependencies: [.product(name: "Hummingbird", package: "hummingbird")])
28+
]
29+
30+
)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the SwiftContainerPlugin open source project
4+
//
5+
// Copyright (c) 2024 Apple Inc. and the SwiftContainerPlugin project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of SwiftContainerPlugin project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
import Foundation
16+
import Hummingbird
17+
18+
let myos = ProcessInfo.processInfo.operatingSystemVersionString
19+
20+
let router = Router()
21+
router.get { request, _ -> String in "Hello World, from Hummingbird on \(myos)\n" }
22+
23+
let app = Application(router: router, configuration: .init(address: .hostname("0.0.0.0", port: 8080)))
24+
25+
try await app.runService()

Examples/HelloWorldVapor/Sources/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ let app = try Application(.detect())
2121
app.http.server.configuration.hostname = "0.0.0.0"
2222
defer { app.shutdown() }
2323

24-
app.get { _ in "Hello World, from \(myos)\n" }
24+
app.get { _ in "Hello World, from Vapor on \(myos)\n" }
2525

2626
try app.run()

NOTICE.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,9 @@ following other projects:
7272
* https://mit-license.org
7373
* HOMEPAGE:
7474
* https://github.com/vapor/vapor
75+
76+
* Hummingbird
77+
* LICENSE (Apache License 2.0):
78+
* https://www.apache.org/licenses/LICENSE-2.0
79+
* HOMEPAGE:
80+
* https://github.com/hummingbird-project/hummingbird

0 commit comments

Comments
 (0)