diff --git a/Sources/YData/Client/InternalResponse+Vapor.swift b/Sources/YData/Client/InternalResponse+Vapor.swift index 03149e4..4b806f0 100644 --- a/Sources/YData/Client/InternalResponse+Vapor.swift +++ b/Sources/YData/Client/InternalResponse+Vapor.swift @@ -18,8 +18,8 @@ public extension EventLoopFuture where Value: InternalResponse { func mapContent(_ callback: @escaping (ContentContainer) throws -> (NewValue)) -> EventLoopFuture where NewValue: Content { flatMapThrowing { try $0.map(callback) } } - func mapToContent() -> EventLoopFuture where R: Decodable { - flatMapThrowing { response -> R in try response.content.decode(R.self) } + func mapToContent(_ type: D.Type = D.self) -> EventLoopFuture { + flatMapThrowing { response -> D in try response.content.decode(type) } } func flatMapContentThrowing(_ callback: @escaping (ContentContainer) throws -> (NewValue)) diff --git a/Sources/YData/Client/InternalResponse.swift b/Sources/YData/Client/InternalResponse.swift index 39648ca..ef87c8d 100644 --- a/Sources/YData/Client/InternalResponse.swift +++ b/Sources/YData/Client/InternalResponse.swift @@ -28,6 +28,11 @@ public extension InternalResponse { return Self.init(headers: headers, status: status, body: nil) } + + @inlinable + func mapToContent(_ type: D.Type = D.self) throws -> D { + try content.decode(type) + } } public extension Internal {