@@ -6,13 +6,13 @@ import XCTestDynamicOverlay
66 import FoundationNetworking
77#endif
88
9- /// A type that can make requests to a server, download the response, and decode the response
10- /// into a model.
9+ /// A type that can make requests to a server, download the response, and decode the response into a
10+ /// model.
1111///
1212/// You do not typically construct this type directly from its initializer, and instead use the
13- /// ``live(router:session:)`` static method for creating an API client from a parser-printer, or
14- /// use the ``failing`` static variable for creating an API client that throws an error when a
15- /// request is made and then use ``override(_:with:)-1ot4o`` to override certain routes with mocked
13+ /// ``live(router:session:)`` static method for creating an API client from a parser-printer, or use
14+ /// the ``failing`` static variable for creating an API client that throws an error when a request
15+ /// is made and then use ``override(_:with:)-1ot4o`` to override certain routes with mocked
1616/// responses.
1717public struct URLRoutingClient < Route> {
1818 var request : ( Route ) async throws -> ( Data , URLResponse )
@@ -26,6 +26,15 @@ public struct URLRoutingClient<Route> {
2626 self . decoder = decoder
2727 }
2828
29+ /// Makes a request to a route.
30+ ///
31+ /// - Parameter route: The route to request.
32+ /// - Returns: The data and response.
33+ @available ( iOS 13 , macOS 10 . 15 , tvOS 13 , watchOS 6 , * )
34+ public func data( for route: Route ) async throws -> ( value: Data , response: URLResponse ) {
35+ try await self . request ( route)
36+ }
37+
2938 /// Makes a request to a route.
3039 ///
3140 /// - Parameters:
@@ -34,12 +43,12 @@ public struct URLRoutingClient<Route> {
3443 /// - decoder: A JSON decoder.
3544 /// - Returns: The decoded value.
3645 @available ( iOS 13 , macOS 10 . 15 , tvOS 13 , watchOS 6 , * )
37- public func request < Value: Decodable > (
38- _ route: Route ,
46+ public func decodedResponse < Value: Decodable > (
47+ for route: Route ,
3948 as type: Value . Type = Value . self,
4049 decoder: JSONDecoder ? = nil
4150 ) async throws -> ( value: Value , response: URLResponse ) {
42- let ( data, response) = try await self . request ( route)
51+ let ( data, response) = try await self . data ( for : route)
4352 do {
4453 return ( try ( decoder ?? self . decoder) . decode ( type, from: data) , response)
4554 } catch {
0 commit comments