@@ -7,7 +7,8 @@ public extension URLServer {
77 /// - endpoint: The endpoint
88 /// - configuring: Optional request configuration to apply before sending
99 /// - Throws: Throws an ``APIError`` if the request fails or server returns an error,
10- /// or an error from ``RequestConfiguring/configure(_:)`` if configuration fails.
10+ /// `EncodingError` if request building fails, or an error from ``RequestConfiguring/configure(_:)``
11+ /// if configuration fails.
1112 func call( endpoint: Endpoint , configuring: RequestConfiguring ? = nil ) async throws {
1213 _ = try await execute ( endpoint: endpoint, configuring: configuring)
1314 }
@@ -17,7 +18,8 @@ public extension URLServer {
1718 /// - endpoint: The endpoint
1819 /// - configuring: Optional request configuration to apply before sending
1920 /// - Throws: Throws an ``APIError`` if the request fails or server returns an error,
20- /// or an error from ``RequestConfiguring/configure(_:)`` if configuration fails.
21+ /// `EncodingError` if request building fails, or an error from ``RequestConfiguring/configure(_:)``
22+ /// if configuration fails.
2123 /// - Returns: Plain data returned with the HTTP Response
2224 func call( data endpoint: Endpoint , configuring: RequestConfiguring ? = nil ) async throws -> Data {
2325 try await execute ( endpoint: endpoint, configuring: configuring) . data
@@ -28,7 +30,8 @@ public extension URLServer {
2830 /// - endpoint: The endpoint
2931 /// - configuring: Optional request configuration to apply before sending
3032 /// - Throws: Throws an ``APIError`` if the request fails or server returns an error,
31- /// or an error from ``RequestConfiguring/configure(_:)`` if configuration fails.
33+ /// `EncodingError` if request building fails, or an error from ``RequestConfiguring/configure(_:)``
34+ /// if configuration fails.
3235 /// - Returns: Instance of the required type
3336 func call< EP: ResponseEndpoint > ( response endpoint: EP , configuring: RequestConfiguring ? = nil ) async throws -> EP . Response {
3437 let result = try await execute ( endpoint: endpoint, configuring: configuring)
@@ -46,10 +49,11 @@ public extension URLServer {
4649 /// - endpoint: The endpoint
4750 /// - configuring: Optional request configuration to apply before sending
4851 /// - Throws: Throws an ``APIError`` if the request fails or server returns an error,
49- /// or an error from ``RequestConfiguring/configure(_:)`` if configuration fails.
52+ /// `EncodingError` if request building fails, or an error from ``RequestConfiguring/configure(_:)``
53+ /// if configuration fails.
5054 /// - Returns: The location of a temporary file where the server's response is stored.
5155 /// You must move this file or open it for reading before the async function returns. Otherwise, the file
52- /// is deleted, and the data is lost.
56+ /// is deleted, and the data is lost. For automatic file management, use ``download(endpoint:destination:configuring:)`` instead.
5357 func download( endpoint: Endpoint , configuring: RequestConfiguring ? = nil ) async throws -> URL {
5458 let ( urlRequest, observers) = try await prepareObservers ( endpoint: endpoint, configuring: configuring)
5559
@@ -67,6 +71,19 @@ public extension URLServer {
6771
6872 return localURL
6973 }
74+
75+ /// Downloads a file from the specified endpoint and moves it to the given destination.
76+ /// - Parameters:
77+ /// - endpoint: The endpoint
78+ /// - destination: The file URL where the downloaded file should be stored
79+ /// - configuring: Optional request configuration to apply before sending
80+ /// - Throws: Throws an ``APIError`` if the request fails or server returns an error,
81+ /// `EncodingError` if request building fails, or an error from ``RequestConfiguring/configure(_:)``
82+ /// if configuration fails.
83+ func download( endpoint: Endpoint , destination: URL , configuring: RequestConfiguring ? = nil ) async throws {
84+ let tempURL = try await download ( endpoint: endpoint, configuring: configuring)
85+ try FileManager . default. moveItem ( at: tempURL, to: destination)
86+ }
7087}
7188
7289// MARK: - Private helpers
0 commit comments