Skip to content

Commit fc19dc6

Browse files
committed
[Fix] Let AI update documentation based on implementation.
1 parent 9b3b52a commit fc19dc6

2 files changed

Lines changed: 87 additions & 57 deletions

File tree

Package.resolved

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 78 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -73,75 +73,62 @@ let userResponse: UserResponse = try await apiManager.request(UserRouter.getUser
7373
## Downloading files
7474
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).
7575
```swift
76-
let (task, response) = try await DownloadAPIManager().request(url: URL)
76+
let (task, response) = try await DownloadAPIManager.shared.downloadRequest(url: URL)
7777
```
7878

7979
You can then observe the download progress for a given `URLSessionDownloadTask`
8080
```swift
8181
for try await 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
8387
}
8488
```
8589

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) = try await DownloadAPIManager.shared.downloadRequest(
94+
endpoint,
95+
resumableData: resumeData, // Optional data to resume a previous download
96+
retryConfiguration: RetryConfiguration.default
97+
)
98+
```
8799

88100
## 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+
90103
```swift
104+
// Upload a file from URL
91105
let uploadTask = try await uploadManager.upload(.file(fileUrl), to: "https://upload.com/file")
106+
107+
// Upload raw data
108+
let uploadTask = try await 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 = try await uploadManager.upload(.multipartFormData(formData), to: "https://upload.com/file")
92114
```
93115

94116
You can then observe the upload progress for a given [UploadTask](https://strvcom.github.io/ios-networking/documentation/networking/uploadtask)
95117
```swift
96118
for await uploadState in await uploadManager.stateStream(for: task.id) {
97-
...
119+
// Handle upload state updates
120+
// uploadState.progress - current progress (0.0 to 1.0)
121+
// uploadState.error - any error that occurred
122+
// uploadState.response - response when complete
98123
}
99124
```
100125

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 = try await 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.
118-
![Interceptors diagram](Sources/Networking/Documentation.docc/Resources/interceptors-diagram.png)
119-
120-
There are three types you can leverage:<br>
121-
122-
[RequestAdapting](https://strvcom.github.io/ios-networking/documentation/networking/requestadapting)
123-
124-
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).
125-
126-
[ResponseProcessing](https://strvcom.github.io/ios-networking/documentation/networking/responseprocessing)
127-
128-
Response processors are handling the ``Response`` received after a successful network request.
129-
130-
[ErrorProcessing](https://strvcom.github.io/ios-networking/documentation/networking/errorprocessing)
131-
132-
Error processors are handling the `Error` received after a failed network request.
133-
134-
[RequestInterceptor](https://strvcom.github.io/ios-networking/documentation/networking/requestinterceptor)
135-
136-
Interceptors handle both adapting and response/error processing.
137-
138-
By conforming to these protocols, you can create your own adaptors/processors/interceptors.
126+
The [UploadAPIManager](https://strvcom.github.io/ios-networking/documentation/networking/uploadapimanager) also provides:
127+
- `activeTasks` property to track current uploads
128+
- `retry(taskId:)` method to retry failed uploads
129+
- `invalidateSession(shouldFinishTasks:)` to clean up resources when done
139130

140-
Here is list of classes provided by this library which implement these protocols:
141-
- [StatusCodeProcessor](https://strvcom.github.io/ios-networking/documentation/networking/statuscodeprocessor)
142-
- [EndpointRequestStorageProcessor](https://strvcom.github.io/ios-networking/documentation/networking/endpointrequeststorageprocessor)
143-
- [LoggingInterceptor](https://strvcom.github.io/ios-networking/documentation/networking/logginginterceptor)
144-
- [AuthorizationTokenInterceptor](https://strvcom.github.io/ios-networking/documentation/networking/authorizationtokeninterceptor)
131+
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`.
145132

146133
## Request authorization
147134
Networking provides a default authorization handling for OAuth scenarios. In order to utilise this we
@@ -201,3 +188,46 @@ var urlParameters: [String: Any]? {
201188
["filter": ArrayParameter([1, 2, 3], arrayEncoding: .individual)]
202189
}
203190
```
191+
192+
## Retry-ability
193+
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 = try await 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.
207+
![Interceptors diagram](Sources/Networking/Documentation.docc/Resources/interceptors-diagram.png)
208+
209+
There are three types you can leverage:<br>
210+
211+
[RequestAdapting](https://strvcom.github.io/ios-networking/documentation/networking/requestadapting)
212+
213+
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).
214+
215+
[ResponseProcessing](https://strvcom.github.io/ios-networking/documentation/networking/responseprocessing)
216+
217+
Response processors are handling the ``Response`` received after a successful network request.
218+
219+
[ErrorProcessing](https://strvcom.github.io/ios-networking/documentation/networking/errorprocessing)
220+
221+
Error processors are handling the `Error` received after a failed network request.
222+
223+
[RequestInterceptor](https://strvcom.github.io/ios-networking/documentation/networking/requestinterceptor)
224+
225+
Interceptors handle both adapting and response/error processing.
226+
227+
By conforming to these protocols, you can create your own adaptors/processors/interceptors.
228+
229+
Here is list of classes provided by this library which implement these protocols:
230+
- [StatusCodeProcessor](https://strvcom.github.io/ios-networking/documentation/networking/statuscodeprocessor)
231+
- [EndpointRequestStorageProcessor](https://strvcom.github.io/ios-networking/documentation/networking/endpointrequeststorageprocessor)
232+
- [LoggingInterceptor](https://strvcom.github.io/ios-networking/documentation/networking/logginginterceptor)
233+
- [AuthorizationTokenInterceptor](https://strvcom.github.io/ios-networking/documentation/networking/authorizationtokeninterceptor)

0 commit comments

Comments
 (0)