Skip to content

Instantly share code, notes, and snippets.

@cmoulton
Created June 29, 2016 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmoulton/a6d090b9dbaba469590f9474c03f9081 to your computer and use it in GitHub Desktop.
Save cmoulton/a6d090b9dbaba469590f9474c03f9081 to your computer and use it in GitHub Desktop.
HTTP Header Auth with Alamofire
func doMashape() -> Void {
let manager = Alamofire.Manager.sharedInstance
let headers = ["X-Mashape-Key": "MY_API_KEY", "Accept": "application/json"]
manager.request(.GET, "https://mashape-community-urban-dictionary.p.mashape.com/define?term=hipster", headers: headers)
.responseString { _, _, result in
if let receivedString = result.value {
print(receivedString)
}
}
}
@durul
Copy link

durul commented Jun 29, 2016

// Alamofire ~> 3.0

func doMashape() -> Void {
    let manager = Alamofire.Manager.sharedInstance
    let headers = ["X-Mashape-Key": "MY_API_KEY", "Accept": "application/json"]
    manager.request(.GET, "https://mashape-community-urban-dictionary.p.mashape.com/define?term=hipster", headers: headers)
        .responseString { response in
            if let receivedString = response.result.value {
                print(receivedString)
            }
    }
}

@cmoulton
Copy link
Author

More options for headers with Swift 3.0/Alamofire 4.0: https://gist.github.com/cmoulton/ab674eb7bcb5aa1a0580fc8ba5176f6b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment