From a8ea24adf21e424bb529c3163b4c84a857b08f48 Mon Sep 17 00:00:00 2001 From: Christian Noon Date: Wed, 15 Jul 2015 18:44:04 -0700 Subject: [PATCH] Added section to the README about new HTTP header support in the global functions. --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index fc71179..c01b1ee 100644 --- a/README.md +++ b/README.md @@ -285,6 +285,24 @@ Alamofire.request(.POST, "http://httpbin.org/post", parameters: parameters, enco // HTTP body: {"foo": [1, 2, 3], "bar": {"baz": "qux"}} ``` +### HTTP Headers + +Adding a custom HTTP header to a `Request` is supported directly in the global `request` method. This makes it easy to attach HTTP headers to a `Request` that can be constantly changing. + +> For HTTP headers that do not change, it is recommended to set them on the `NSURLSessionConfiguration` so they are automatically applied to any `NSURLSessionTask` created by the underlying `NSURLSession`. + +```swift +let headers = [ + "Authorization", "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==", + "Content-Type": "application/x-www-form-urlencoded" +] + +Alamofire.request(.GET, "http://httpbin.org/get", headers: headers) + .responseJSON { _, _, JSON, _ in + println(JSON) + } +``` + ### Caching Caching is handled on the system framework level by [`NSURLCache`](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSURLCache_Class/Reference/Reference.html#//apple_ref/occ/cl/NSURLCache). -- GitLab