Skip to content

Commit

Permalink
add content about the Response object.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdisho authored Oct 29, 2019
1 parent 85c80ba commit a9fb045
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,30 @@ import TinyNetworking

let tinyNetworking = TinyNetworking<Unsplash>()

tinyNetworking.request(.photo(id: "1234")) { response in
switch response {
case let .success(result):
let photo = try? result.map(to: Photo.self)
tinyNetworking.request(.photo(id: "1234")) { result in
switch result {
case let .success(response):
let photo = try? response.map(to: Photo.self)
print(photo)
case let .error(error):
print(error)
}
}
```

### 🔖 Response
After making a request, `TinyNetworking` gives a result back in the form of `Result<Response, TinyNetworkingError>`, which has two cases to `switch` over. In case of success, a `Response` object is given, otherwise an error.

The `Response` object gives the possibility to use:
- Raw data from the request.
- The `URLRequest` object.
- The HTTP response.
- Debug description.
- The JSON repdesentation of the data.
- The pretty printed version of the data in a JSON format.
- Method to map/decode the data to a decodable object. A decodable object, is an object that conforms to `Codable` (`Decodable+Encodable`) protocol.


## 🐍 Reactive Extensions
Reactive extensions are cool. TinyNetworking provides reactive extensions for Combine, RxSwift and **soon** for ReactiveSwift.

Expand Down

0 comments on commit a9fb045

Please sign in to comment.