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
Reactive wrapper for URLSession using Combine. At its core, the library consist of the `NetworkServiceClient` protocol along with a minimal implementation `NetworkService`.
7
+
Async wrapper and dependency injection layer for URLSession. At its core, the library consist of the `NetworkServiceClient` protocol along with a minimal implementation `NetworkService`.
8
8
9
9
### TopLevelCodable
10
10
A notable convenience the library provides is the `TopLevelCodable` protocol that enables easy encoding and decoding of conforming types. The protocol associates a `TopLevelEncoder` and `TopLevelDecoder` with a given type so that it is used by the library without explicitly passing it as a parameter. Additionally, `TopLevelEncodable` and `TopLevelDecodable` are included.
@@ -23,42 +23,39 @@ let foo = Foo(bar: 0)
23
23
```
24
24
#### GET
25
25
```swift
26
-
let publisher: AnyPublisher<Foo, Failuer> = networkService.get(url)
27
-
let cancellable = publisher.assertNoFailure().sink { foo in
28
-
print(foo.bar)
29
-
}
26
+
let result: Result<Foo, NetworkService.Failure> =await networkService.get(url)
27
+
let foo =try result.get()
28
+
print(foo.bar)
30
29
```
31
30
32
31
#### POST
33
32
```swift
34
-
let publisher: AnyPublisher<Foo, Failuer> = networkService.post(foo, to: url)
35
-
let cancellable = publisher.assertNoFailure().sink { foo in
36
-
print(foo.bar)
37
-
}
33
+
let result: Result<Foo, NetworkService.Failure> =await networkService.post(foo, to: url)
34
+
let foo =try result.get()
35
+
print(foo.bar)
38
36
```
39
37
40
38
#### PUT
41
39
```swift
42
-
let publisher: AnyPublisher<Foo, Failuer> = networkService.put(foo, to: url)
43
-
let cancellable = publisher.assertNoFailure().sink { foo in
44
-
print(foo.bar)
45
-
}
40
+
let result: Result<Foo, NetworkService.Failure> =await networkService.put(foo, to: url)
41
+
let foo =try result.get()
42
+
print(foo.bar)
46
43
```
47
44
48
45
#### DELETE
49
46
```swift
50
-
let publisher: AnyPublisher<Foo, Failuer> = networkService.get(url)
51
-
let cancellable = publisher.assertNoFailure().sink { _in }
47
+
let result: Result<Foo, NetworkService.Failure> =await networkService.get(url)
48
+
let foo =try result.get()
49
+
print(foo.bar)
52
50
```
53
51
54
52
#### Start
55
53
```swift
56
54
var request =URLRequest(url: url)
57
55
request.method= .GET
58
-
let publisher: AnyPublisher<Foo, Failuer> = networkService.start(request)
59
-
let cancellable = publisher.assertNoFailure().sink { foo in
0 commit comments