diff --git a/Starter/Package.resolved b/Starter/Package.resolved index d6d7bed..8c1f913 100644 --- a/Starter/Package.resolved +++ b/Starter/Package.resolved @@ -14,8 +14,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/hummingbird-project/hummingbird.git", "state" : { - "revision" : "8cb3e42b6bffa4c78cf424bde0490c911a56f073", - "version" : "2.0.0-alpha.3" + "revision" : "dd3663447be43bb3c813579960715c110c66bb18", + "version" : "2.0.0-beta.1" } }, { @@ -104,8 +104,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-nio.git", "state" : { - "revision" : "635b2589494c97e48c62514bc8b37ced762e0a62", - "version" : "2.63.0" + "revision" : "fc63f0cf4e55a4597407a9fc95b16a2bc44b4982", + "version" : "2.64.0" } }, { @@ -113,8 +113,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-nio-extras.git", "state" : { - "revision" : "363da63c1966405764f380c627409b2f9d9e710b", - "version" : "1.21.0" + "revision" : "a3b640d7dc567225db7c94386a6e71aded1bfa63", + "version" : "1.22.0" } }, { @@ -167,8 +167,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/swift-server/swift-service-lifecycle.git", "state" : { - "revision" : "55f45e39dd23c6cad82d4d529e22961cb5e493aa", - "version" : "2.4.0" + "revision" : "d7fe0e731499a8dcce53bf4cbbc812c8e565d3a7", + "version" : "2.4.1" } }, { diff --git a/Starter/Package.swift b/Starter/Package.swift index c981e06..787d13c 100644 --- a/Starter/Package.swift +++ b/Starter/Package.swift @@ -7,7 +7,7 @@ let package = Package( .macOS(.v14), ], dependencies: [ - .package(url: "https://github.com/hummingbird-project/hummingbird.git", from: "2.0.0-alpha.3"), + .package(url: "https://github.com/hummingbird-project/hummingbird.git", from: "2.0.0-beta.1"), .package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.0.0"), ], targets: [ @@ -23,7 +23,7 @@ let package = Package( name: "AppTests", dependencies: [ .target(name: "App"), - .product(name: "HummingbirdXCT", package: "hummingbird"), + .product(name: "HummingbirdTesting", package: "hummingbird"), ] ), ] diff --git a/Starter/Sources/App/Application+build.swift b/Starter/Sources/App/Application+build.swift index a125bff..4a131c6 100644 --- a/Starter/Sources/App/Application+build.swift +++ b/Starter/Sources/App/Application+build.swift @@ -2,13 +2,13 @@ import Foundation import Hummingbird import Logging -func buildApplication() async throws -> some HBApplicationProtocol { +func buildApplication() async throws -> some ApplicationProtocol { - let router = HBRouter(context: MyBaseRequestContext.self) + let router = Router(context: MyBaseRequestContext.self) - router.middlewares.add(HBLogRequestsMiddleware(.info)) - router.middlewares.add(HBFileMiddleware()) - router.middlewares.add(HBCORSMiddleware( + router.middlewares.add(LogRequestsMiddleware(.info)) + router.middlewares.add(FileMiddleware()) + router.middlewares.add(CORSMiddleware( allowOrigin: .originBased, allowHeaders: [.contentType], allowMethods: [.get, .post, .delete, .patch] @@ -20,7 +20,7 @@ func buildApplication() async throws -> some HBApplicationProtocol { MyController().addRoutes(to: router.group("api")) - return HBApplication( + return Application( router: router, configuration: .init( address: .hostname("localhost", port: 8080) diff --git a/Starter/Sources/App/Controllers/MyController.swift b/Starter/Sources/App/Controllers/MyController.swift index 150f232..f21c816 100644 --- a/Starter/Sources/App/Controllers/MyController.swift +++ b/Starter/Sources/App/Controllers/MyController.swift @@ -5,7 +5,7 @@ import NIO struct MyController { func addRoutes( - to group: HBRouterGroup + to group: RouterGroup ) { group .get(use: list) @@ -14,7 +14,7 @@ struct MyController { @Sendable func list( - _ request: HBRequest, + _ request: Request, context: Context ) async throws -> [MyModel] { [ @@ -26,9 +26,9 @@ struct MyController { @Sendable func create( - _ request: HBRequest, + _ request: Request, context: Context - ) async throws -> HBEditedResponse { + ) async throws -> EditedResponse { // context.myValue let input = try await request.decode( as: MyModel.self, diff --git a/Starter/Sources/App/Models/MyModel.swift b/Starter/Sources/App/Models/MyModel.swift index 6faf52b..b4554b1 100644 --- a/Starter/Sources/App/Models/MyModel.swift +++ b/Starter/Sources/App/Models/MyModel.swift @@ -4,4 +4,4 @@ struct MyModel: Codable { let title: String } -extension MyModel: HBResponseCodable {} +extension MyModel: ResponseCodable {} diff --git a/Starter/Sources/App/RequestContexts/MyRequestContext.swift b/Starter/Sources/App/RequestContexts/MyRequestContext.swift index ae03e47..1d46dc1 100644 --- a/Starter/Sources/App/RequestContexts/MyRequestContext.swift +++ b/Starter/Sources/App/RequestContexts/MyRequestContext.swift @@ -2,13 +2,13 @@ import Hummingbird import Logging import NIOCore -protocol MyRequestContext: HBRequestContext { +protocol MyRequestContext: RequestContext { var myValue: String? { get set } } struct MyBaseRequestContext: MyRequestContext { - var coreContext: HBCoreRequestContext + var coreContext: CoreRequestContext var myValue: String? init( @@ -22,7 +22,7 @@ struct MyBaseRequestContext: MyRequestContext { self.myValue = nil } - var requestDecoder: HBRequestDecoder { + var requestDecoder: RequestDecoder { MyRequestDecoder() } } diff --git a/Starter/Sources/App/RequestDecoders/MyRequestDecoder.swift b/Starter/Sources/App/RequestDecoders/MyRequestDecoder.swift index 4f4bcb2..8607cc3 100644 --- a/Starter/Sources/App/RequestDecoders/MyRequestDecoder.swift +++ b/Starter/Sources/App/RequestDecoders/MyRequestDecoder.swift @@ -1,26 +1,26 @@ import Hummingbird -struct MyRequestDecoder: HBRequestDecoder { +struct MyRequestDecoder: RequestDecoder { func decode( _ type: T.Type, - from request: HBRequest, - context: some HBBaseRequestContext + from request: Request, + context: some BaseRequestContext ) async throws -> T where T: Decodable { guard let header = request.headers[.contentType] else { - throw HBHTTPError(.badRequest) + throw HTTPError(.badRequest) } - guard let mediaType = HBMediaType(from: header) else { - throw HBHTTPError(.badRequest) + guard let mediaType = MediaType(from: header) else { + throw HTTPError(.badRequest) } - let decoder: HBRequestDecoder + let decoder: RequestDecoder switch mediaType { case .applicationJson: decoder = JSONDecoder() case .applicationUrlEncoded: decoder = URLEncodedFormDecoder() default: - throw HBHTTPError(.badRequest) + throw HTTPError(.badRequest) } return try await decoder.decode( type,