From 81bbf65143bd57f7fcca55078ef5f7b362b296ab Mon Sep 17 00:00:00 2001 From: Euan Harris Date: Mon, 30 Sep 2024 11:06:43 +0100 Subject: [PATCH] Examples: Add a Hello World example using Hummingbird --- Examples/HelloWorldHummingbird/.gitignore | 8 + .../HelloWorldHummingbird/Package.resolved | 204 ++++++++++++++++++ Examples/HelloWorldHummingbird/Package.swift | 30 +++ .../HelloWorldHummingbird/Sources/main.swift | 25 +++ Examples/HelloWorldVapor/Sources/main.swift | 2 +- NOTICE.txt | 6 + 6 files changed, 274 insertions(+), 1 deletion(-) create mode 100644 Examples/HelloWorldHummingbird/.gitignore create mode 100644 Examples/HelloWorldHummingbird/Package.resolved create mode 100644 Examples/HelloWorldHummingbird/Package.swift create mode 100644 Examples/HelloWorldHummingbird/Sources/main.swift diff --git a/Examples/HelloWorldHummingbird/.gitignore b/Examples/HelloWorldHummingbird/.gitignore new file mode 100644 index 0000000..0023a53 --- /dev/null +++ b/Examples/HelloWorldHummingbird/.gitignore @@ -0,0 +1,8 @@ +.DS_Store +/.build +/Packages +xcuserdata/ +DerivedData/ +.swiftpm/configuration/registries.json +.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata +.netrc diff --git a/Examples/HelloWorldHummingbird/Package.resolved b/Examples/HelloWorldHummingbird/Package.resolved new file mode 100644 index 0000000..9b6a3d7 --- /dev/null +++ b/Examples/HelloWorldHummingbird/Package.resolved @@ -0,0 +1,204 @@ +{ + "originHash" : "2f3ac8faf8689600adc30e65a0df976a76c71e7a7eab1e21727045478315c6d6", + "pins" : [ + { + "identity" : "async-http-client", + "kind" : "remoteSourceControl", + "location" : "https://github.com/swift-server/async-http-client.git", + "state" : { + "revision" : "64abc77edf1ef81e69bd90a2ac386de615c8e8ea", + "version" : "1.23.0" + } + }, + { + "identity" : "hummingbird", + "kind" : "remoteSourceControl", + "location" : "https://github.com/hummingbird-project/hummingbird.git", + "state" : { + "revision" : "913e6a0b4bd9c1c0efd399cd870c47187e74d00e", + "version" : "2.1.0" + } + }, + { + "identity" : "swift-algorithms", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-algorithms.git", + "state" : { + "revision" : "f6919dfc309e7f1b56224378b11e28bab5bccc42", + "version" : "1.2.0" + } + }, + { + "identity" : "swift-argument-parser", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-argument-parser", + "state" : { + "revision" : "41982a3656a71c768319979febd796c6fd111d5c", + "version" : "1.5.0" + } + }, + { + "identity" : "swift-async-algorithms", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-async-algorithms.git", + "state" : { + "revision" : "6ae9a051f76b81cc668305ceed5b0e0a7fd93d20", + "version" : "1.0.1" + } + }, + { + "identity" : "swift-atomics", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-atomics.git", + "state" : { + "revision" : "cd142fd2f64be2100422d658e7411e39489da985", + "version" : "1.2.0" + } + }, + { + "identity" : "swift-collections", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-collections.git", + "state" : { + "revision" : "671108c96644956dddcd89dd59c203dcdb36cec7", + "version" : "1.1.4" + } + }, + { + "identity" : "swift-container-plugin", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-container-plugin", + "state" : { + "revision" : "5b6a2583cbc9109c77795cd4eaf94b4a1e88f7eb", + "version" : "0.1.0" + } + }, + { + "identity" : "swift-crypto", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-crypto.git", + "state" : { + "revision" : "ffca28be3c9c6a86a579949d23f68818a4b9b5d8", + "version" : "3.8.0" + } + }, + { + "identity" : "swift-distributed-tracing", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-distributed-tracing.git", + "state" : { + "revision" : "11c756c5c4d7de0eeed8595695cadd7fa107aa19", + "version" : "1.1.1" + } + }, + { + "identity" : "swift-http-types", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-http-types.git", + "state" : { + "revision" : "ae67c8178eb46944fd85e4dc6dd970e1f3ed6ccd", + "version" : "1.3.0" + } + }, + { + "identity" : "swift-log", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-log.git", + "state" : { + "revision" : "9cb486020ebf03bfa5b5df985387a14a98744537", + "version" : "1.6.1" + } + }, + { + "identity" : "swift-metrics", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-metrics.git", + "state" : { + "revision" : "e0165b53d49b413dd987526b641e05e246782685", + "version" : "2.5.0" + } + }, + { + "identity" : "swift-nio", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio.git", + "state" : { + "revision" : "665206000b8307cab5ac51203d29b0f232d7e31b", + "version" : "2.74.0" + } + }, + { + "identity" : "swift-nio-extras", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio-extras.git", + "state" : { + "revision" : "d1ead62745cc3269e482f1c51f27608057174379", + "version" : "1.24.0" + } + }, + { + "identity" : "swift-nio-http2", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio-http2.git", + "state" : { + "revision" : "b5f7062b60e4add1e8c343ba4eb8da2e324b3a94", + "version" : "1.34.0" + } + }, + { + "identity" : "swift-nio-ssl", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio-ssl.git", + "state" : { + "revision" : "7b84abbdcef69cc3be6573ac12440220789dcd69", + "version" : "2.27.2" + } + }, + { + "identity" : "swift-nio-transport-services", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio-transport-services.git", + "state" : { + "revision" : "38ac8221dd20674682148d6451367f89c2652980", + "version" : "1.21.0" + } + }, + { + "identity" : "swift-numerics", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-numerics.git", + "state" : { + "revision" : "0a5bc04095a675662cf24757cc0640aa2204253b", + "version" : "1.0.2" + } + }, + { + "identity" : "swift-service-context", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-service-context.git", + "state" : { + "revision" : "0c62c5b4601d6c125050b5c3a97f20cce881d32b", + "version" : "1.1.0" + } + }, + { + "identity" : "swift-service-lifecycle", + "kind" : "remoteSourceControl", + "location" : "https://github.com/swift-server/swift-service-lifecycle.git", + "state" : { + "revision" : "24c800fb494fbee6e42bc156dc94232dc08971af", + "version" : "2.6.1" + } + }, + { + "identity" : "swift-system", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-system.git", + "state" : { + "revision" : "d2ba781702a1d8285419c15ee62fd734a9437ff5", + "version" : "1.3.2" + } + } + ], + "version" : 3 +} diff --git a/Examples/HelloWorldHummingbird/Package.swift b/Examples/HelloWorldHummingbird/Package.swift new file mode 100644 index 0000000..0ce3201 --- /dev/null +++ b/Examples/HelloWorldHummingbird/Package.swift @@ -0,0 +1,30 @@ +// swift-tools-version: 6.0 + +//===----------------------------------------------------------------------===// +// +// This source file is part of the SwiftContainerPlugin open source project +// +// Copyright (c) 2024 Apple Inc. and the SwiftContainerPlugin project authors +// Licensed under Apache License v2.0 +// +// See LICENSE.txt for license information +// See CONTRIBUTORS.txt for the list of SwiftContainerPlugin project authors +// +// SPDX-License-Identifier: Apache-2.0 +// +//===----------------------------------------------------------------------===// + +import PackageDescription + +let package = Package( + name: "hello-world", + platforms: [.macOS(.v14)], + dependencies: [ + .package(url: "https://github.com/hummingbird-project/hummingbird.git", from: "2.1.0"), + .package(url: "https://github.com/apple/swift-container-plugin", from: "0.1.0"), + ], + targets: [ + .executableTarget(name: "hello-world", dependencies: [.product(name: "Hummingbird", package: "hummingbird")]) + ] + +) diff --git a/Examples/HelloWorldHummingbird/Sources/main.swift b/Examples/HelloWorldHummingbird/Sources/main.swift new file mode 100644 index 0000000..ae980aa --- /dev/null +++ b/Examples/HelloWorldHummingbird/Sources/main.swift @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the SwiftContainerPlugin open source project +// +// Copyright (c) 2024 Apple Inc. and the SwiftContainerPlugin project authors +// Licensed under Apache License v2.0 +// +// See LICENSE.txt for license information +// See CONTRIBUTORS.txt for the list of SwiftContainerPlugin project authors +// +// SPDX-License-Identifier: Apache-2.0 +// +//===----------------------------------------------------------------------===// + +import Foundation +import Hummingbird + +let myos = ProcessInfo.processInfo.operatingSystemVersionString + +let router = Router() +router.get { request, _ -> String in "Hello World, from Hummingbird on \(myos)\n" } + +let app = Application(router: router, configuration: .init(address: .hostname("0.0.0.0", port: 8080))) + +try await app.runService() diff --git a/Examples/HelloWorldVapor/Sources/main.swift b/Examples/HelloWorldVapor/Sources/main.swift index 97479ee..780ad41 100644 --- a/Examples/HelloWorldVapor/Sources/main.swift +++ b/Examples/HelloWorldVapor/Sources/main.swift @@ -21,6 +21,6 @@ let app = try Application(.detect()) app.http.server.configuration.hostname = "0.0.0.0" defer { app.shutdown() } -app.get { _ in "Hello World, from \(myos)\n" } +app.get { _ in "Hello World, from Vapor on \(myos)\n" } try app.run() diff --git a/NOTICE.txt b/NOTICE.txt index d98b010..7e24d58 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -72,3 +72,9 @@ following other projects: * https://mit-license.org * HOMEPAGE: * https://github.com/vapor/vapor + + * Hummingbird + * LICENSE (Apache License 2.0): + * https://www.apache.org/licenses/LICENSE-2.0 + * HOMEPAGE: + * https://github.com/hummingbird-project/hummingbird