You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Downloads are being handled by a designated [DownloadAPIManager](https://strvcom.github.io/ios-networking/documentation/networking/downloadapimanager). Here is an example of a basic form of file download from a `URL`. It returns a tuple of `URLSessionDownloadTask` and [Response](https://strvcom.github.io/ios-networking/documentation/networking/response) (result for the HTTP handshake).
75
75
```swift
76
-
let (task, response) =tryawaitDownloadAPIManager().request(url: URL)
76
+
let (task, response) =tryawait DownloadAPIManager.shared.downloadRequest(url: URL)
77
77
```
78
78
79
79
You can then observe the download progress for a given `URLSessionDownloadTask`
80
80
```swift
81
81
fortryawait downloadState in downloadAPIManager.shared.progressStream(for: task) {
82
-
...
82
+
// Handle download state updates
83
+
// downloadState.downloadedBytes - current progress
84
+
// downloadState.totalBytes - total size
85
+
// downloadState.downloadedFileURL - final file location when complete
86
+
// downloadState.error - any error that occurred
83
87
}
84
88
```
85
89
86
-
In case you need to provide some specific info in the request, you can define a type conforming to [Requestable](https://strvcom.github.io/ios-networking/documentation/networking/requestable) protocol and pass that to the [DownloadAPIManager](https://strvcom.github.io/ios-networking/documentation/networking/downloadapimanager) instead of the `URL`.
90
+
In case you need to provide some specific info in the request, you can define a type conforming to [Requestable](https://strvcom.github.io/ios-networking/documentation/networking/requestable) protocol and pass that to the [DownloadAPIManager](https://strvcom.github.io/ios-networking/documentation/networking/downloadapimanager) instead of the `URL`. You can also configure retry behavior and handle resumable downloads:
91
+
92
+
```swift
93
+
let (task, response) =tryawait DownloadAPIManager.shared.downloadRequest(
94
+
endpoint,
95
+
resumableData: resumeData, // Optional data to resume a previous download
96
+
retryConfiguration: RetryConfiguration.default
97
+
)
98
+
```
87
99
88
100
## Uploading files
89
-
Uploads are being handled by a designated [UploadAPIManager](https://strvcom.github.io/ios-networking/documentation/networking/uploadapimanager). Here is an example of a basic form of file upload to a `URL`. It returns an [UploadTask](https://strvcom.github.io/ios-networking/documentation/networking/uploadtask) which is a struct that represents + manages a `URLSessionUploadTask` and provides its state.
101
+
Uploads are being handled by a designated [UploadAPIManager](https://strvcom.github.io/ios-networking/documentation/networking/uploadapimanager). Here is an example of a basic form of file upload to a `URL`. It returns an [UploadTask](https://strvcom.github.io/ios-networking/documentation/networking/uploadtask) which is a struct that represents and manages a `URLSessionUploadTask` and provides its state.
102
+
90
103
```swift
104
+
// Upload a file from URL
91
105
let uploadTask =tryawait uploadManager.upload(.file(fileUrl), to: "https://upload.com/file")
106
+
107
+
// Upload raw data
108
+
let uploadTask =tryawait uploadManager.upload(.data(data), to: "https://upload.com/file")
109
+
110
+
// Upload multipart form data
111
+
let formData =MultipartFormData()
112
+
formData.append(fileUrl, withName: "file")
113
+
let uploadTask =tryawait uploadManager.upload(.multipartFormData(formData), to: "https://upload.com/file")
92
114
```
93
115
94
116
You can then observe the upload progress for a given [UploadTask](https://strvcom.github.io/ios-networking/documentation/networking/uploadtask)
// uploadState.progress - current progress (0.0 to 1.0)
121
+
// uploadState.error - any error that occurred
122
+
// uploadState.response - response when complete
98
123
}
99
124
```
100
125
101
-
In case you need to provide some specific info in the request, you can define a type conforming to [Requestable](https://strvcom.github.io/ios-networking/documentation/networking/requestable) protocol and pass that to the [UploadAPIManager](https://strvcom.github.io/ios-networking/documentation/networking/uploadapimanager) instead of the upload `URL`.
102
-
103
-
## Retry-ability
104
-
Both [APIManager](https://strvcom.github.io/ios-networking/documentation/networking/apimanager) and [DownloadAPIManager](https://strvcom.github.io/ios-networking/documentation/networking/downloadapimanager) allow for configurable retry mechanism. You can provide a custom after failure [RetryConfiguration](https://strvcom.github.io/ios-networking/documentation/networking/retryconfiguration), specifying the count of retries, delay and a handler that determines whether the request should be tried again. Otherwise, [RetryConfiguration.default](https://strvcom.github.io/ios-networking/documentation/networking/retryconfiguration/default) configuration is used.
105
-
106
-
```swift
107
-
let retryConfiguration =RetryConfiguration(retries: 2, delay: .constant(1)) { error in
108
-
// custom logic here
109
-
}
110
-
let userResponse: UserResponse =tryawait apiManager.request(
111
-
UserRouter.getUser,
112
-
retryConfiguration: retryConfiguration
113
-
)
114
-
```
115
-
116
-
## Modifiers
117
-
Modifiers are useful pieces of code that modify request/response in the network request pipeline.
Adapters are request transformable components that perform operations on the URLRequest before it is dispatched. They are used to further customise HTTP requests before they are carried out by editing the URLRequest (e.g updating headers).
In case you need to provide some specific info in the request, you can define a type conforming to [Requestable](https://strvcom.github.io/ios-networking/documentation/networking/requestable) protocol and pass that to the [UploadAPIManager](https://strvcom.github.io/ios-networking/documentation/networking/uploadapimanager) instead of the upload `URL`.
145
132
146
133
## Request authorization
147
134
Networking provides a default authorization handling for OAuth scenarios. In order to utilise this we
@@ -201,3 +188,46 @@ var urlParameters: [String: Any]? {
Both [APIManager](https://strvcom.github.io/ios-networking/documentation/networking/apimanager) and [DownloadAPIManager](https://strvcom.github.io/ios-networking/documentation/networking/downloadapimanager) allow for configurable retry mechanism. You can provide a custom after failure [RetryConfiguration](https://strvcom.github.io/ios-networking/documentation/networking/retryconfiguration), specifying the count of retries, delay and a handler that determines whether the request should be tried again. Otherwise, [RetryConfiguration.default](https://strvcom.github.io/ios-networking/documentation/networking/retryconfiguration/default) configuration is used.
194
+
195
+
```swift
196
+
let retryConfiguration =RetryConfiguration(retries: 2, delay: .constant(1)) { error in
197
+
// custom logic here
198
+
}
199
+
let userResponse: UserResponse =tryawait apiManager.request(
200
+
UserRouter.getUser,
201
+
retryConfiguration: retryConfiguration
202
+
)
203
+
```
204
+
205
+
## Modifiers
206
+
Modifiers are useful pieces of code that modify request/response in the network request pipeline.
Adapters are request transformable components that perform operations on the URLRequest before it is dispatched. They are used to further customise HTTP requests before they are carried out by editing the URLRequest (e.g updating headers).
0 commit comments