Structures
The following structures are available globally.
-
A wrapper which will contain the decoded
T
instance, if one was successfully decoded; otherwisenil
.OptionalResponseType
is useful for when you have a request which may or may not return the expected JSON structure. For example, fetching a mythicalUserDetails
JSON for a user who does not exist, but for reason - unbeknownst to us - the server return no JSON instead of a 404.Example:
struct UserDetails { var mothersMaidenName: String var lovesTheDentist: Bool } struct UserDetailsRequest: Codable { var userId: Int } extension UserDetailsRequest: Interceptable, Gettable { typealias ResponseType = OptionalResponseType<UserDetails> var path: String = "/some/api/path" } UserDetailsRequest(userId: 42).submit() { result in if case let Result.success(optionalUserDetails) = result { let userDetails = optionalUserDetails.instance } }
See moreDeclaration
Swift
public struct OptionalResponseType<T>: Decodable where T: Decodable