Skip to content

Instantly share code, notes, and snippets.

@mhijack
Last active April 7, 2021 05:59
Show Gist options
  • Save mhijack/822dc8d6a5e8df300f9684ade158919e to your computer and use it in GitHub Desktop.
Save mhijack/822dc8d6a5e8df300f9684ade158919e to your computer and use it in GitHub Desktop.
Evolution of handling API response with Alamofire
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