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
Copy file name to clipboardExpand all lines: CHANGELOG.md
+12-3Lines changed: 12 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,13 +5,22 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
5
5
6
6
## [Unreleased]
7
7
### Added
8
-
- None.
8
+
- New `ApiProvider` type encapsulating different request methods with support for plugins.
9
+
- New asynchronous `performRequest` methods with completion callbacks. ([#2](https://github.com/Flinesoft/Microya/issues/2))
10
+
- New `Plugin` class to subclass for integrating into the networking logic via callbacks.
11
+
- New pre-implemented plugins: `HttpBasicAuth`, `ProgressIndicator`, `RequestLogger`, `ResponseLogger`.
12
+
- New `EmptyResponseBody` type to use whenever the body is expected to be empty or should be ignored.
9
13
### Changed
10
-
- None.
14
+
- Renamed `JsonApi` protocol to `Endpoint`.
15
+
- Renamed `Method` to `HttpMethod` and added `body: Data` to the cases `post` and `patch`.
16
+
- Moved the `request` method from `JsonApi` to the new `ApiProvider` & renamed to `performRequestAndWait`.
17
+
- Generally improved the cases in `JsonApiError` & renamed the type to `ApiError`.
18
+
- Moved CI from [Bitrise](https://www.bitrise.io/) to [GitHub Actions](https://github.com/Flinesoft/Microya/actions).
11
19
### Deprecated
12
20
- None.
13
21
### Removed
14
-
- None.
22
+
- The `bodyData: Data?` requirement on `JsonApi` (bodies are not part of `HttpMethod`, see above).
23
+
- Installation is no longer possible via [CocoaPods](https://github.com/CocoaPods/CocoaPods) or [Carthage](https://github.com/Carthage/Carthage). Please use [SwiftPM](https://github.com/apple/swift-package-manager) instead.
### Step 3: Calling your API endpoint with the Result type
186
174
187
-
Call an API endpoint providing a `Decodable` type of the expected result (if any) by using this method pre-implemented in the `JsonApi` protocol:
175
+
Call an API endpoint providing a `Decodable` type of the expected result (if any) by using one of the methods pre-implemented in the `ApiProvider` type:
// use the already decoded `[String: String]` result
201
225
202
-
caselet .failure(error):
226
+
caselet .failure(apiError):
203
227
// error handling
204
228
}
205
229
```
206
230
207
231
Note that you can also use the throwing `get()` function of Swift 5's `Result` type instead of using a `switch` statement:
208
232
209
233
```Swift
210
-
let endpoint = MicrosoftTranslatorApi.translate(texts: ["Test"], from: .english, to: [.german, .japanese, .turkish])
211
-
let translationsByLanguage =try endpoint.request(type: [String:String].self).get()
234
+
provider.performRequest(on: endpoint, decodeBodyTo: [String:String].self) { result in
235
+
let translationsByLanguage =try result.get()
236
+
// use the already decoded `[String: String]` result
237
+
}
238
+
239
+
// OR, if you prefere a synchronous call, use the `AndWait` variant
240
+
241
+
let translationsByLanguage =try provider.performRequestAndWait(on: endpoint, decodeBodyTo: [String:String].self).get()
212
242
// use the already decoded `[String: String]` result
213
243
```
214
244
215
245
There's even useful functional methods defined on the `Result` type like `map()`, `flatMap()` or `mapError()` and `flatMapError()`. See the "Transforming Result" section in [this](https://www.hackingwithswift.com/articles/161/how-to-use-result-in-swift) article for more information.
216
246
247
+
### Plugins
248
+
249
+
The initializer of `ApiProvider` accepts an array of `Plugin` objects. You can implement your own plugins or use one of the existing ones in the [Plugins](https://github.com/Flinesoft/Microya/tree/main/Sources/Microya/Plugins) directory. Here's are the callbacks a custom `Plugin` subclass can override:
0 commit comments