ExternalView
public class ExternalView : APIView
Collection of functions for invoking requests to external servers other than Zone5 The purpose for using the Zone5 library for sending requests to external servers is to utilise the shared Cognito token and make use of the inbuilt token refresh functionality
-
Perform a request via the given method with the given endpoint.
Note that if you pass a body with a method that does not support a body you will get an unexpectedRequestBody exception
Declaration
Swift
@discardableResult public func requestDecode<T>(_ endpoint: RequestEndpoint, method: Zone5.Method, headers: [String : String]? = nil, keyDecodingStrategy: JSONDecoder.KeyDecodingStrategy = .useDefaultKeys, parameters queryParams: URLEncodedBody? = nil, body: RequestBody? = nil, type: T.Type = T.self, completion completionHandler: @escaping Completion<T>) -> PendingRequest? where T : Decodable
-
Perform a request and instead of decoding the response pass back the raw Data and URLResponse
Declaration
Swift
@discardableResult public func request(_ endpoint: RequestEndpoint, method: Zone5.Method, headers: [String : String]? = nil, parameters queryParams: URLEncodedBody? = nil, body: RequestBody? = nil, completion completionHandler: @escaping (_ result: Result<(Data?, URLResponse), Zone5.Error>) -> Void) -> PendingRequest?
-
Upload the given file via a POST request with the given endpoint.
Declaration
Swift
@discardableResult public func postUpload<T>(_ endpoint: RequestEndpoint, file fileURL: URL, headers: [String : String]? = nil, keyDecodingStrategy: JSONDecoder.KeyDecodingStrategy = .useDefaultKeys, parameters queryParams: URLEncodedBody? = nil, body: RequestBody? = nil, type: T.Type = T.self, completion completionHandler: @escaping Completion<T>) -> PendingRequest? where T : Decodable
-
Upload the given file via a PUT request with the geiven endpoint.
Declaration
Swift
@discardableResult public func putUpload<T>(_ endpoint: RequestEndpoint, file fileURL: URL, headers: [String : String]? = nil, keyDecodingStrategy: JSONDecoder.KeyDecodingStrategy = .useDefaultKeys, parameters queryParams: URLEncodedBody? = nil, body: RequestBody? = nil, type: T.Type = T.self, completion completionHandler: @escaping Completion<T>) -> PendingRequest? where T : Decodable
-
Download a file with the given endpoint. This is a get request so may contain query parameters but no body
Declaration
Swift
@discardableResult public func download(_ endpoint: RequestEndpoint, headers: [String : String]? = nil, queryParams: URLEncodedBody? = nil, progressHandler: ((_ bytesWritten: Int64, _ totalBytesWritten: Int64, _ totalBytesExpectedToWrite: Int64) -> Void)? = nil, completionHandler: @escaping Completion<URL>) -> PendingRequest?