Last active
April 7, 2021 05:59
-
-
Save mhijack/822dc8d6a5e8df300f9684ade158919e to your computer and use it in GitHub Desktop.
Evolution of handling API response with Alamofire
This file contains 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
func signup() { | |
let headers: HTTPHeaders? = ["Content-Type": "application/x-www-form-urlencoded", | |
"Access-Token": "Bearer abcdefgasmyaccesstoken"] | |
AF.request("http://myserver.com/", | |
method: .post, | |
parameters: nil, | |
encoding: URLEncoding.default, | |
headers: headers, | |
interceptor: nil) | |
.response(completionHandler: { dataResponse in | |
if dataResponse.response?.statusCode == 201 { | |
// Handle 201 success | |
} else if dataResponse.response?.statusCode == 409 { | |
// Handle 409 error | |
} else { | |
// Handle Unknown error | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment