Last active
June 15, 2021 00:22
-
-
Save barefeettom/fd5fd8cd531e92af51fc8daf3dee6f43 to your computer and use it in GitHub Desktop.
Fetchable. For article: https://medium.com/p/4ddf8710d1a0/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public protocol Fetchable { | |
// Required. No default values: | |
/// The type of the object in the response. | |
associatedtype Fetched | |
/// The type of the failure object in the response. | |
associatedtype FetchedFailure | |
/// The parameter keys, to be used in the request. | |
associatedtype Key: FetchKey | |
/// The base URL for the request. Typically `URL("https://host/common_path/")!` | |
static var baseURL: URL { get } | |
// Can override. Default values: | |
/// End point first path component. Defaults to `nil`. | |
static var startURLPath: String? { get } | |
/// End point last path component. Defaults to lowercase of `Fetched` type. | |
static var endURLPath: String? { get } | |
/// Defaults to `.get`. Can also be `.post`. | |
static var httpMethod: Fetch.HTTPMethod { get } | |
/// Defaults to `.form` when `httpMethod` = `.get` and `.json` when `httpMethod` = `.post`. | |
static var encoding: Fetch.Encoding { get } | |
/// Defaults to nil. | |
static var headers: [String: String]? { get } | |
/// Defaults to `JSONDecoder` with `dateDecodingStrategy` = `.iso8601`. Can change to `.sqlDate` or `.tTimezone` or `.timezone` or custom. | |
static var decoder: JSONDecoder { get } | |
/// Default key values, such as an API key or authorization. Defaults to empty. | |
static var defaultKeyValues: [Key : FetchValue] { get } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment