Skip to content

Instantly share code, notes, and snippets.

@Rashidium
Last active August 20, 2021 07:48
Show Gist options
  • Save Rashidium/73b44552054e357fa826a77568cea3aa to your computer and use it in GitHub Desktop.
Save Rashidium/73b44552054e357fa826a77568cea3aa to your computer and use it in GitHub Desktop.
import Alamofire
...
func login() {
let urlStr = "\(serverUrl)\(EndpointTails.login.rawValue)"
AF.request(urlStr, method: .get).responseDecodable { (response: DataResponse<PanpaResponse<User>, AFError>) in
if let panpaResponse = response.value {
switch panpaResponse.status {
case .success:
guard let user: User = panpaResponse.data else { return }
print(user.username)
case .failed:
print("API error with message: \(panpaResponse.message)")
}
} else {
let errorResponse = PanpaResponse<User>()
print("API error with message: \(errorResponse.message)")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment