From a9fb0457adee0f834725a3c9836cf1ab8eccc965 Mon Sep 17 00:00:00 2001 From: Joan Disho Date: Tue, 29 Oct 2019 14:09:32 +0100 Subject: [PATCH] add content about the Response object. --- README.md | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7cf65f9..bda6f2e 100644 --- a/README.md +++ b/README.md @@ -105,10 +105,10 @@ import TinyNetworking let tinyNetworking = TinyNetworking() -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) @@ -116,6 +116,19 @@ tinyNetworking.request(.photo(id: "1234")) { response in } ``` +### 🔖 Response +After making a request, `TinyNetworking` gives a result back in the form of `Result`, 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.