Skip to content

Instantly share code, notes, and snippets.

@aalemi97
Last active October 14, 2020 10:10
Show Gist options
  • Save aalemi97/6d0fa73f1ce12e8cbb4f5f4e32c51cdb to your computer and use it in GitHub Desktop.
Save aalemi97/6d0fa73f1ce12e8cbb4f5f4e32c51cdb to your computer and use it in GitHub Desktop.
func request(_ url: String, method: HTTPMethod = .get, parameters: Parameters? = nil,
encoding: ParameterEncoding = URLEncoding.queryString, headers: HTTPHeaders? = nil,
interceptor: RequestInterceptor? = nil, completion: @escaping completionHandler) {
AF.request(url, method: method, parameters: parameters, encoding: encoding,
headers: headers, interceptor: interceptor ?? self).validate().responseJSON { (response) in
if let data = response.data {
completion(.success(data))
} else {
completion(.failure(.unavailableServer))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment