README.md 42.6 KB
Newer Older
M
Mattt Thompson 已提交
1
![Alamofire: Elegant Networking in Swift](https://raw.githubusercontent.com/Alamofire/Alamofire/assets/alamofire.png)
M
Mattt Thompson 已提交
2

3
[![Build Status](https://travis-ci.org/Alamofire/Alamofire.svg)](https://travis-ci.org/Alamofire/Alamofire)
4
[![Cocoapods Compatible](https://img.shields.io/cocoapods/v/Alamofire.svg)](https://img.shields.io/cocoapods/v/Alamofire.svg)
5 6 7
[![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
[![Platform](https://img.shields.io/cocoapods/p/Alamofire.svg?style=flat)](http://cocoadocs.org/docsets/Alamofire)
[![Twitter](https://img.shields.io/badge/twitter-@AlamofireSF-blue.svg?style=flat)](http://twitter.com/AlamofireSF)
8

M
Mattt Thompson 已提交
9
Alamofire is an HTTP networking library written in Swift.
10 11 12

## Features

M
- [x]  
Mattt Thompson 已提交
13 14
- [x] Chainable Request / Response methods
- [x] URL / JSON / plist Parameter Encoding
15
- [x] Upload File / Data / Stream / MultipartFormData
M
- [x]  
Mattt Thompson 已提交
16 17 18
- [x] Download using Request or Resume data
- [x] Authentication with NSURLCredential
- [x] HTTP Response Validation
19
- [x] TLS Certificate and Public Key Pinning
M
- [x]  
Mattt Thompson 已提交
20 21 22
- [x] Progress Closure & NSProgress
- [x] cURL Debug Output
- [x] Comprehensive Unit Test Coverage
R
rojotek 已提交
23
- [x] [Complete Documentation](http://cocoadocs.org/docsets/Alamofire)
24 25 26

## Requirements

27
- iOS 8.0+ / Mac OS X 10.9+ / watchOS 2
28
- Xcode 7.0+
29

30 31
## Migration Guides

32
- [Alamofire 3.0 Migration Guide](https://github.com/Alamofire/Alamofire/blob/master/Documentation/Alamofire%203.0%20Migration%20Guide.md)
33
- [Alamofire 2.0 Migration Guide](https://github.com/Alamofire/Alamofire/blob/master/Documentation/Alamofire%202.0%20Migration%20Guide.md)
34

M
Mattt Thompson 已提交
35 36 37 38 39 40 41 42
## Communication

- If you **need help**, use [Stack Overflow](http://stackoverflow.com/questions/tagged/alamofire). (Tag 'alamofire')
- If you'd like to **ask a general question**, use [Stack Overflow](http://stackoverflow.com/questions/tagged/alamofire).
- If you **found a bug**, open an issue.
- If you **have a feature request**, open an issue.
- If you **want to contribute**, submit a pull request.

43 44
## Installation

45
> **Embedded frameworks require a minimum deployment target of iOS 8 or OS X Mavericks (10.9).**
M
Mattt Thompson 已提交
46
>
47
> Alamofire is no longer supported on iOS 7 due to the lack of support for frameworks. Without frameworks, running Travis-CI against iOS 7 would require a second duplicated test target. The separate test suite would need to import all the Swift files and the tests would need to be duplicated and re-written. This split would be too difficult to maintain to ensure the highest possible quality of the Alamofire ecosystem.
48

49 50 51 52
### CocoaPods

[CocoaPods](http://cocoapods.org) is a dependency manager for Cocoa projects.

53
CocoaPods 0.38.2 is required to build Alamofire on the `swift-2.0` branch. It adds support for Xcode 7, Swift 2.0 and embedded frameworks. You can install it with the following command:
54 55

```bash
56
$ gem install cocoapods
57 58 59 60 61 62 63
```

To integrate Alamofire into your Xcode project using CocoaPods, specify it in your `Podfile`:

```ruby
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
64
use_frameworks!
65

66
pod 'Alamofire', '~> 2.0'
67 68 69 70 71 72 73 74 75 76
```

Then, run the following command:

```bash
$ pod install
```

### Carthage

J
Josh Brown 已提交
77
[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.
78 79 80 81 82 83 84 85 86 87 88

You can install Carthage with [Homebrew](http://brew.sh/) using the following command:

```bash
$ brew update
$ brew install carthage
```

To integrate Alamofire into your Xcode project using Carthage, specify it in your `Cartfile`:

```ogdl
89
github "Alamofire/Alamofire" ~> 2.0
90 91 92 93 94 95
```

### Manually

If you prefer not to use either of the aforementioned dependency managers, you can integrate Alamofire into your project manually.

96
#### Embedded Framework
97

98 99 100 101 102 103 104
- Open up Terminal, `cd` into your top-level project directory, and run the following command "if" your project is not initialized as a git repository:

```bash
$ git init
```

- Add Alamofire as a git [submodule](http://git-scm.com/docs/git-submodule) by running the following command:
105 106 107 108 109

```bash
$ git submodule add https://github.com/Alamofire/Alamofire.git
```

110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
- Open the new `Alamofire` folder, and drag the `Alamofire.xcodeproj` into the Project Navigator of your application's Xcode project.

    > It should appear nested underneath your application's blue project icon. Whether it is above or below all the other Xcode groups does not matter.

- Select the `Alamofire.xcodeproj` in the Project Navigator and verify the deployment target matches that of your application target.
- Next, select your application project in the Project Navigator (blue project icon) to navigate to the target configuration window and select the application target under the "Targets" heading in the sidebar.
- In the tab bar at the top of that window, open the "General" panel.
- Click on the `+` button under the "Embedded Binaries" section.
- You will see two different `Alamofire.xcodeproj` folders each with two different versions of the `Alamofire.framework` nested inside a `Products` folder.

    > It does not matter which `Products` folder you choose from, but it does matter whether you choose the top or bottom `Alamofire.framework`. 
    
- Select the top `Alamofire.framework` for iOS and the bottom one for OS X.

    > You can verify which one you selected by inspecting the build log for your project. The build target for `Alamofire` will be listed as either `Alamofire iOS` or `Alamofire OSX`.

- And that's it!

128
> The `Alamofire.framework` is automagically added as a target dependency, linked framework and embedded framework in a copy files build phase which is all you need to build on the simulator and a device.
129

130 131
---

M
Mattt Thompson 已提交
132 133
## Usage

M
Mattt Thompson 已提交
134
### Making a Request
M
Mattt Thompson 已提交
135 136

```swift
M
Mattt Thompson 已提交
137 138
import Alamofire

M
Mattt Thompson 已提交
139 140 141
Alamofire.request(.GET, "http://httpbin.org/get")
```

M
Mattt Thompson 已提交
142
### Response Handling
M
Mattt Thompson 已提交
143 144

```swift
145
Alamofire.request(.GET, "http://httpbin.org/get", parameters: ["foo": "bar"])
146 147 148 149 150 151 152 153 154 155
         .responseJSON { response in
             print(response.request)  // original URL request
             print(response.response) // URL response
             print(response.data)     // server data
             print(response.result)   // result of response serialization

             if let JSON = response.result.value {
                 print("JSON: \(JSON)")
             }
         }
M
Mattt Thompson 已提交
156 157
```

M
Mattt Thompson 已提交
158 159
> Networking in Alamofire is done _asynchronously_. Asynchronous programming may be a source of frustration to programmers unfamiliar with the concept, but there are [very good reasons](https://developer.apple.com/library/ios/qa/qa1693/_index.html) for doing it this way.

M
Mattt Thompson 已提交
160
> Rather than blocking execution to wait for a response from the server, a [callback](http://en.wikipedia.org/wiki/Callback_%28computer_programming%29) is specified to handle the response once it's received. The result of a request is only available inside the scope of a response handler. Any execution contingent on the response or data received from the server must be done within a handler.
M
Mattt Thompson 已提交
161 162 163 164 165

### Response Serialization

**Built-in Response Methods**

166
- `response()`
167
- `responseData()`
M
Mattt Thompson 已提交
168 169 170 171
- `responseString(encoding: NSStringEncoding)`
- `responseJSON(options: NSJSONReadingOptions)`
- `responsePropertyList(options: NSPropertyListReadOptions)`

172
#### Response Handler
173 174 175

```swift
Alamofire.request(.GET, "http://httpbin.org/get", parameters: ["foo": "bar"])
176
         .response { request, response, data, error in
177 178 179 180 181 182 183
             print(request)
             print(response)
             print(data)
             print(error)
          }
```

184 185 186 187 188 189 190 191 192 193 194 195 196
> The `response` serializer does NOT evaluate any of the response data. It merely forwards on all the information directly from the URL session delegate. We strongly encourage you to leverage the other responser serializers taking advantage of `Response` and `Result` types.

#### Response Data Handler

```swift
Alamofire.request(.GET, "http://httpbin.org/get", parameters: ["foo": "bar"])
         .responseData { response in
             print(response.request)
             print(response.response)
             print(response.result)
          }
```

197
#### Response String Handler
M
Mattt Thompson 已提交
198 199 200

```swift
Alamofire.request(.GET, "http://httpbin.org/get")
201 202 203
         .responseString { response in
             print("Success: \(response.result.isSuccess)")
             print("Response String: \(response.result.value)")
M
Mattt Thompson 已提交
204 205 206
         }
```

207
#### Response JSON Handler
M
Mattt Thompson 已提交
208 209

```swift
M
Mattt Thompson 已提交
210
Alamofire.request(.GET, "http://httpbin.org/get")
211 212
         .responseJSON { response in
             debugPrint(response)
M
Mattt Thompson 已提交
213 214 215
         }
```

M
Mattt Thompson 已提交
216 217 218 219 220 221
#### Chained Response Handlers

Response handlers can even be chained:

```swift
Alamofire.request(.GET, "http://httpbin.org/get")
222 223
         .responseString { response in
             print("Response String: \(response.result.value)")
M
Mattt Thompson 已提交
224
         }
225 226
         .responseJSON { response in
             print("Response JSON: \(response.result.value)")
M
Mattt Thompson 已提交
227 228 229
         }
```

M
Mattt Thompson 已提交
230 231
### HTTP Methods

M
Mattt Thompson 已提交
232
`Alamofire.Method` lists the HTTP methods defined in [RFC 7231 §4.3](http://tools.ietf.org/html/rfc7231#section-4.3):
M
Mattt Thompson 已提交
233 234 235

```swift
public enum Method: String {
236
    case OPTIONS, GET, HEAD, POST, PUT, PATCH, DELETE, TRACE, CONNECT
M
Mattt Thompson 已提交
237 238 239 240 241 242 243 244 245 246 247 248 249
}
```

These values can be passed as the first argument of the `Alamofire.request` method:

```swift
Alamofire.request(.POST, "http://httpbin.org/post")

Alamofire.request(.PUT, "http://httpbin.org/put")

Alamofire.request(.DELETE, "http://httpbin.org/delete")
```

M
Mattt Thompson 已提交
250 251 252 253 254 255 256 257 258 259
### Parameters

#### GET Request With URL-Encoded Parameters

```swift
Alamofire.request(.GET, "http://httpbin.org/get", parameters: ["foo": "bar"])
// http://httpbin.org/get?foo=bar
```

#### POST Request With URL-Encoded Parameters
M
Mattt Thompson 已提交
260 261 262 263 264 265 266 267 268 269 270 271

```swift
let parameters = [
    "foo": "bar",
    "baz": ["a", 1],
    "qux": [
        "x": 1,
        "y": 2,
        "z": 3
    ]
]

M
Mattt Thompson 已提交
272
Alamofire.request(.POST, "http://httpbin.org/post", parameters: parameters)
M
Mattt Thompson 已提交
273
// HTTP body: foo=bar&baz[]=a&baz[]=1&qux[x]=1&qux[y]=2&qux[z]=3
M
Mattt Thompson 已提交
274 275 276 277
```

### Parameter Encoding

M
Mattt Thompson 已提交
278
Parameters can also be encoded as JSON, Property List, or any custom format, using the `ParameterEncoding` enum:
M
Mattt Thompson 已提交
279

M
Mattt Thompson 已提交
280 281 282
```swift
enum ParameterEncoding {
    case URL
283
    case URLEncodedInURL
284
    case JSON
285 286
    case PropertyList(format: NSPropertyListFormat, options: NSPropertyListWriteOptions)
    case Custom((URLRequestConvertible, [String: AnyObject]?) -> (NSMutableURLRequest, NSError?))
M
Mattt Thompson 已提交
287

288
    func encode(request: NSURLRequest, parameters: [String: AnyObject]?) -> (NSURLRequest, NSError?)
M
Mattt Thompson 已提交
289 290 291 292
    { ... }
}
```

A
Aaron Brager 已提交
293
- `URL`: A query string to be set as or appended to any existing URL query for `GET`, `HEAD`, and `DELETE` requests, or set as the body for requests with any other HTTP method. The `Content-Type` HTTP header field of an encoded request with HTTP body is set to `application/x-www-form-urlencoded`. _Since there is no published specification for how to encode collection types, Alamofire follows the convention of appending `[]` to the key for array values (`foo[]=1&foo[]=2`), and appending the key surrounded by square brackets for nested dictionary values (`foo[bar]=baz`)._
294
- `URLEncodedInURL`: Creates query string to be set as or appended to any existing URL query. Uses the same implementation as the `.URL` case, but always applies the encoded result to the URL.
M
Mattt Thompson 已提交
295 296 297 298
- `JSON`: Uses `NSJSONSerialization` to create a JSON representation of the parameters object, which is set as the body of the request. The `Content-Type` HTTP header field of an encoded request is set to `application/json`.
- `PropertyList`: Uses `NSPropertyListSerialization` to create a plist representation of the parameters object, according to the associated format and write options values, which is set as the body of the request. The `Content-Type` HTTP header field of an encoded request is set to `application/x-plist`.
- `Custom`: Uses the associated closure value to construct a new request given an existing request and parameters.

M
Mattt Thompson 已提交
299 300 301
#### Manual Parameter Encoding of an NSURLRequest

```swift
302
let URL = NSURL(string: "http://httpbin.org/get")!
303
var request = NSMutableURLRequest(URL: URL)
M
Mattt Thompson 已提交
304 305 306

let parameters = ["foo": "bar"]
let encoding = Alamofire.ParameterEncoding.URL
P
Petr Korolev 已提交
307
(request, _) = encoding.encode(request, parameters: parameters)
M
Mattt Thompson 已提交
308 309
```

M
Mattt Thompson 已提交
310
#### POST Request with JSON-encoded Parameters
M
Mattt Thompson 已提交
311 312

```swift
M
Mattt Thompson 已提交
313 314 315 316 317 318 319
let parameters = [
    "foo": [1,2,3],
    "bar": [
        "baz": "qux"
    ]
]

320
Alamofire.request(.POST, "http://httpbin.org/post", parameters: parameters, encoding: .JSON)
M
Mattt Thompson 已提交
321
// HTTP body: {"foo": [1, 2, 3], "bar": {"baz": "qux"}}
M
Mattt Thompson 已提交
322 323
```

324 325 326 327 328 329 330 331
### 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 = [
F
fewspider 已提交
332
    "Authorization": "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==",
333 334 335 336
    "Content-Type": "application/x-www-form-urlencoded"
]

Alamofire.request(.GET, "http://httpbin.org/get", headers: headers)
337 338
         .responseJSON { response in
             debugPrint(response)
339 340 341
         }
```

M
Mattt Thompson 已提交
342
### Caching
M
Mattt Thompson 已提交
343

M
Mattt Thompson 已提交
344
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).
M
Mattt Thompson 已提交
345 346 347

### Uploading

M
Mattt Thompson 已提交
348
**Supported Upload Types**
M
Mattt Thompson 已提交
349 350 351 352

- File
- Data
- Stream
353
- MultipartFormData
M
Mattt Thompson 已提交
354 355 356 357

#### Uploading a File

```swift
358
let fileURL = NSBundle.mainBundle().URLForResource("Default", withExtension: "png")
359
Alamofire.upload(.POST, "http://httpbin.org/post", file: fileURL)
M
Mattt Thompson 已提交
360 361
```

362
#### Uploading with Progress
M
Mattt Thompson 已提交
363 364

```swift
365
Alamofire.upload(.POST, "http://httpbin.org/post", file: fileURL)
366
         .progress { bytesWritten, totalBytesWritten, totalBytesExpectedToWrite in
367
             print(totalBytesWritten)
368 369 370

             // This closure is NOT called on the main queue for performance
             // reasons. To update your ui, dispatch to the main queue.
371
             dispatch_async(dispatch_get_main_queue()) {
372 373
                 print("Total bytes written on main queue: \(totalBytesWritten)")
             }
M
Mattt Thompson 已提交
374
         }
375 376
         .responseJSON { response in
             debugPrint(response)
M
Mattt Thompson 已提交
377
         }
M
Mattt Thompson 已提交
378 379
```

380 381 382 383 384
#### Uploading MultipartFormData

```swift
Alamofire.upload(
    .POST,
385
    "http://httpbin.org/post",
386 387 388 389 390 391 392
    multipartFormData: { multipartFormData in
        multipartFormData.appendBodyPart(fileURL: unicornImageURL, name: "unicorn")
        multipartFormData.appendBodyPart(fileURL: rainbowImageURL, name: "rainbow")
    },
    encodingCompletion: { encodingResult in
    	switch encodingResult {
    	case .Success(let upload, _, _):
393 394
            upload.responseJSON { response in
                debugPrint(response)
395
            }
396
    	case .Failure(let encodingError):
397
    	    print(encodingError)
398 399 400 401 402
    	}
    }
)
```

M
Mattt Thompson 已提交
403 404
### Downloading

M
Mattt Thompson 已提交
405
**Supported Download Types**
M
Mattt Thompson 已提交
406 407 408 409 410 411 412

- Request
- Resume Data

#### Downloading a File

```swift
413
Alamofire.download(.GET, "http://httpbin.org/stream/100") { temporaryURL, response in
414
    let fileManager = NSFileManager.defaultManager()
415 416
    let directoryURL = fileManager.URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0]
    let pathComponent = response.suggestedFilename
M
Mattt Thompson 已提交
417

418
    return directoryURL.URLByAppendingPathComponent(pathComponent!)
419
}
M
Mattt Thompson 已提交
420 421
```

M
Mattt Thompson 已提交
422
#### Using the Default Download Destination
M
Mattt Thompson 已提交
423 424

```swift
425 426 427
let destination = Alamofire.Request.suggestedDownloadDestination(directory: .DocumentDirectory, domain: .UserDomainMask)
Alamofire.download(.GET, "http://httpbin.org/stream/100", destination: destination)
```
M
Mattt Thompson 已提交
428 429 430 431

#### Downloading a File w/Progress

```swift
432
Alamofire.download(.GET, "http://httpbin.org/stream/100", destination: destination)
433
         .progress { bytesRead, totalBytesRead, totalBytesExpectedToRead in
434
             print(totalBytesRead)
435 436 437

             // This closure is NOT called on the main queue for performance
             // reasons. To update your ui, dispatch to the main queue.
438
             dispatch_async(dispatch_get_main_queue()) {
439 440
                 print("Total bytes read on main queue: \(totalBytesRead)")
             }
M
Mattt Thompson 已提交
441
         }
442 443 444 445 446 447
         .response { _, _, _, error in
             if let error = error {
                 print("Failed with error: \(error)")
             } else {
                 print("Downloaded file successfully")
             }
M
Mattt Thompson 已提交
448 449 450
         }
```

451 452 453 454
#### Accessing Resume Data for Failed Downloads

```swift
Alamofire.download(.GET, "http://httpbin.org/stream/100", destination: destination)
455
         .response { _, _, data, _ in
456
             if let
457
                 data = data,
458 459 460 461 462 463 464 465 466 467 468 469 470
                 resumeDataString = NSString(data: data, encoding: NSUTF8StringEncoding)
             {
                 print("Resume Data: \(resumeDataString)")
             } else {
                 print("Resume Data was empty")
             }
         }
```

> The `data` parameter is automatically populated with the `resumeData` if available.

```swift
let download = Alamofire.download(.GET, "http://httpbin.org/stream/100", destination: destination)
471
download.response { _, _, _, _ in
472 473
    if let
        resumeData = download.resumeData,
474
        resumeDataString = NSString(data: resumeData, encoding: NSUTF8StringEncoding)
475 476 477 478 479 480 481 482
    {
        print("Resume Data: \(resumeDataString)")
    } else {
        print("Resume Data was empty")
    }
}
```

M
Mattt Thompson 已提交
483 484
### Authentication

M
Mattt Thompson 已提交
485 486
Authentication is handled on the system framework level by [`NSURLCredential` and `NSURLAuthenticationChallenge`](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSURLAuthenticationChallenge_Class/Reference/Reference.html).

M
Mattt Thompson 已提交
487
**Supported Authentication Schemes**
M
Mattt Thompson 已提交
488

M
Mattt Thompson 已提交
489 490 491 492
- [HTTP Basic](http://en.wikipedia.org/wiki/Basic_access_authentication)
- [HTTP Digest](http://en.wikipedia.org/wiki/Digest_access_authentication)
- [Kerberos](http://en.wikipedia.org/wiki/Kerberos_%28protocol%29)
- [NTLM](http://en.wikipedia.org/wiki/NT_LAN_Manager)
M
Mattt Thompson 已提交
493 494 495

#### HTTP Basic Authentication

496 497
The `authenticate` method on a `Request` will automatically provide an `NSURLCredential` to an `NSURLAuthenticationChallenge` when appropriate:

M
Mattt Thompson 已提交
498 499 500 501 502
```swift
let user = "user"
let password = "password"

Alamofire.request(.GET, "https://httpbin.org/basic-auth/\(user)/\(password)")
M
Mattt Thompson 已提交
503
         .authenticate(user: user, password: password)
504 505
         .responseJSON { response in
             debugPrint(response)
M
Mattt Thompson 已提交
506
         }
M
Mattt Thompson 已提交
507 508
```

509 510 511 512 513 514 515
Depending upon your server implementation, an `Authorization` header may also be appropriate:

```swift
let user = "user"
let password = "password"

let credentialData = "\(user):\(password)".dataUsingEncoding(NSUTF8StringEncoding)!
516
let base64Credentials = credentialData.base64EncodedStringWithOptions([])
517 518 519 520

let headers = ["Authorization": "Basic \(base64Credentials)"]

Alamofire.request(.GET, "http://httpbin.org/basic-auth/user/password", headers: headers)
521
         .responseJSON { response in
522
             debugPrint(response)
523 524 525
         }
```

M
Mattt Thompson 已提交
526
#### Authentication with NSURLCredential
M
Mattt Thompson 已提交
527 528 529 530 531

```swift
let user = "user"
let password = "password"

532
let credential = NSURLCredential(user: user, password: password, persistence: .ForSession)
M
Mattt Thompson 已提交
533 534

Alamofire.request(.GET, "https://httpbin.org/basic-auth/\(user)/\(password)")
M
Mattt Thompson 已提交
535
         .authenticate(usingCredential: credential)
536 537
         .responseJSON { response in
             debugPrint(response)
M
Mattt Thompson 已提交
538
         }
M
Mattt Thompson 已提交
539 540
```

M
Mattt Thompson 已提交
541 542
### Validation

M
Mattt Thompson 已提交
543 544
By default, Alamofire treats any completed request to be successful, regardless of the content of the response. Calling `validate` before a response handler causes an error to be generated if the response had an unacceptable status code or MIME type.

M
Mattt Thompson 已提交
545
#### Manual Validation
M
Mattt Thompson 已提交
546 547 548 549 550

```swift
Alamofire.request(.GET, "http://httpbin.org/get", parameters: ["foo": "bar"])
         .validate(statusCode: 200..<300)
         .validate(contentType: ["application/json"])
551 552
         .response { response in
             print(response)
M
Mattt Thompson 已提交
553 554 555
         }
```

M
Mattt Thompson 已提交
556
#### Automatic Validation
M
Mattt Thompson 已提交
557 558 559 560 561 562

Automatically validates status code within `200...299` range, and that the `Content-Type` header of the response matches the `Accept` header of the request, if one is provided.

```swift
Alamofire.request(.GET, "http://httpbin.org/get", parameters: ["foo": "bar"])
         .validate()
563 564
         .responseJSON { response in
             switch response.result {
565 566
             case .Success:
                 print("Validation Successful")
567
             case .Failure(let error):
568 569
                 print(error)
             }
M
Mattt Thompson 已提交
570 571 572
         }
```

M
Mattt Thompson 已提交
573 574 575 576 577
### Printable

```swift
let request = Alamofire.request(.GET, "http://httpbin.org/ip")

578
print(request)
M
Mattt Thompson 已提交
579 580 581 582 583 584
// GET http://httpbin.org/ip (200)
```

### DebugPrintable

```swift
585
let request = Alamofire.request(.GET, "http://httpbin.org/get", parameters: ["foo": "bar"])
M
Mattt Thompson 已提交
586

587
debugPrint(request)
M
Mattt Thompson 已提交
588 589 590 591
```

#### Output (cURL)

592
```bash
M
Mattt Thompson 已提交
593 594 595 596 597 598 599
$ curl -i \
	-H "User-Agent: Alamofire" \
	-H "Accept-Encoding: Accept-Encoding: gzip;q=1.0,compress;q=0.5" \
	-H "Accept-Language: en;q=1.0,fr;q=0.9,de;q=0.8,zh-Hans;q=0.7,zh-Hant;q=0.6,ja;q=0.5" \
	"http://httpbin.org/get?foo=bar"
```

M
Mattt Thompson 已提交
600 601 602
---

## Advanced Usage
M
Mattt Thompson 已提交
603

M
Mattt Thompson 已提交
604
> Alamofire is built on `NSURLSession` and the Foundation URL Loading System. To make the most of
M
Mattt Thompson 已提交
605
this framework, it is recommended that you be familiar with the concepts and capabilities of the underlying networking stack.
M
Mattt Thompson 已提交
606

M
Mattt Thompson 已提交
607
**Recommended Reading**
M
Mattt Thompson 已提交
608

M
Mattt Thompson 已提交
609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625
- [URL Loading System Programming Guide](https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/URLLoadingSystem/URLLoadingSystem.html)
- [NSURLSession Class Reference](https://developer.apple.com/library/mac/documentation/Foundation/Reference/NSURLSession_class/Introduction/Introduction.html#//apple_ref/occ/cl/NSURLSession)
- [NSURLCache Class Reference](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSURLCache_Class/Reference/Reference.html#//apple_ref/occ/cl/NSURLCache)
- [NSURLAuthenticationChallenge Class Reference](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSURLAuthenticationChallenge_Class/Reference/Reference.html)

### Manager

Top-level convenience methods like `Alamofire.request` use a shared instance of `Alamofire.Manager`, which is configured with the default `NSURLSessionConfiguration`.

As such, the following two statements are equivalent:

```swift
Alamofire.request(.GET, "http://httpbin.org/get")
```

```swift
let manager = Alamofire.Manager.sharedInstance
626
manager.request(NSURLRequest(URL: NSURL(string: "http://httpbin.org/get")!))
M
Mattt Thompson 已提交
627 628
```

M
Mattt Thompson 已提交
629
Applications can create managers for background and ephemeral sessions, as well as new managers that customize the default session configuration, such as for default headers (`HTTPAdditionalHeaders`) or timeout interval (`timeoutIntervalForRequest`).
M
Mattt Thompson 已提交
630 631 632 633 634 635 636 637 638 639 640

#### Creating a Manager with Default Configuration

```swift
let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
let manager = Alamofire.Manager(configuration: configuration)
```

#### Creating a Manager with Background Configuration

```swift
D
David F. Muir V 已提交
641
let configuration = NSURLSessionConfiguration.backgroundSessionConfigurationWithIdentifier("com.example.app.background")
M
Mattt Thompson 已提交
642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669
let manager = Alamofire.Manager(configuration: configuration)
```

#### Creating a Manager with Ephemeral Configuration

```swift
let configuration = NSURLSessionConfiguration.ephemeralSessionConfiguration()
let manager = Alamofire.Manager(configuration: configuration)
```

#### Modifying Session Configuration

```swift
var defaultHeaders = Alamofire.Manager.sharedInstance.session.configuration.HTTPAdditionalHeaders ?? [:]
defaultHeaders["DNT"] = "1 (Do Not Track Enabled)"

let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
configuration.HTTPAdditionalHeaders = defaultHeaders

let manager = Alamofire.Manager(configuration: configuration)
```

> This is **not** recommended for `Authorization` or `Content-Type` headers. Instead, use `URLRequestConvertible` and `ParameterEncoding`, respectively.

### Request

The result of a `request`, `upload`, or `download` method is an instance of `Alamofire.Request`. A request is always created using a constructor method from an owning manager, and never initialized directly.

670
Methods like `authenticate`, `validate` and `responseData` return the caller in order to facilitate chaining.
M
Mattt Thompson 已提交
671 672 673 674 675 676 677

Requests can be suspended, resumed, and cancelled:

- `suspend()`: Suspends the underlying task and dispatch queue
- `resume()`: Resumes the underlying task and dispatch queue. If the owning manager does not have `startRequestsImmediately` set to `true`, the request must call `resume()` in order to start.
- `cancel()`: Cancels the underlying task, producing an error that is passed to any registered response handlers.

678 679 680 681
### Response Serialization

#### Creating a Custom Response Serializer

M
Mattt Thompson 已提交
682 683 684
Alamofire provides built-in response serialization for strings, JSON, and property lists, but others can be added in extensions on `Alamofire.Request`.

For example, here's how a response handler using [Ono](https://github.com/mattt/Ono) might be implemented:
685 686 687

```swift
extension Request {
688 689 690 691
    public static func XMLResponseSerializer() -> ResponseSerializer<ONOXMLDocument, NSError> {
        return ResponseSerializer { request, response, data, error in
            guard error == nil else { return .Failure(error!) }

692 693 694
            guard let validData = data else {
                let failureReason = "Data could not be serialized. Input data was nil."
                let error = Error.errorWithCode(.DataSerializationFailed, failureReason: failureReason)
695
                return .Failure(error)
696 697
            }

698 699
            do {
                let XML = try ONOXMLDocument(data: validData)
700
                return .Success(XML)
701
            } catch {
702
                return .Failure(error as NSError)
703
            }
704 705 706
        }
    }

707
    public func responseXMLDocument(completionHandler: Response<ONOXMLDocument, NSError> -> Void) -> Self {
708
        return response(responseSerializer: Request.XMLResponseSerializer(), completionHandler: completionHandler)
709 710 711 712 713 714 715 716 717
    }
}
```

#### Generic Response Object Serialization

Generics can be used to provide automatic, type-safe response object serialization.

```swift
718
public protocol ResponseObjectSerializable {
719
    init?(response: NSHTTPURLResponse, representation: AnyObject)
720 721
}

722
extension Request {
723 724 725 726
    public func responseObject<T: ResponseObjectSerializable>(completionHandler: Response<T, NSError> -> Void) -> Self {
        let responseSerializer = ResponseSerializer<T, NSError> { request, response, data, error in
            guard error == nil else { return .Failure(error!) }

727
            let JSONResponseSerializer = Request.JSONResponseSerializer(options: .AllowFragments)
728
            let result = JSONResponseSerializer.serializeResponse(request, response, data, error)
729 730 731 732 733 734 735 736 737 738

            switch result {
            case .Success(let value):
                if let
                    response = response,
                    responseObject = T(response: response, representation: value)
                {
                    return .Success(responseObject)
                } else {
                    let failureReason = "JSON could not be serialized into response object: \(value)"
739
                    let error = Error.errorWithCode(.JSONSerializationFailed, failureReason: failureReason)
740
                    return .Failure(error)
741
                }
742 743
            case .Failure(let error):
                return .Failure(error)
744 745 746
            }
        }

747
        return response(responseSerializer: responseSerializer, completionHandler: completionHandler)
748 749 750 751 752
    }
}
```

```swift
753
final class User: ResponseObjectSerializable {
754 755 756
    let username: String
    let name: String

757
    init?(response: NSHTTPURLResponse, representation: AnyObject) {
758 759
        self.username = response.URL!.lastPathComponent!
        self.name = representation.valueForKeyPath("name") as! String
760 761 762 763 764
    }
}
```

```swift
765 766 767
Alamofire.request(.GET, "https://example.com/users/mattt")
         .responseObject { (response: Response<User, NSError>) in
             debugPrint(response)
768 769 770 771 772 773
         }
```

The same approach can also be used to handle endpoints that return a representation of a collection of objects:

```swift
774 775
public protocol ResponseCollectionSerializable {
    static func collection(response response: NSHTTPURLResponse, representation: AnyObject) -> [Self]
776 777 778
}

extension Alamofire.Request {
779 780 781 782
    public func responseCollection<T: ResponseCollectionSerializable>(completionHandler: Response<[T], NSError> -> Void) -> Self {
        let responseSerializer = ResponseSerializer<[T], NSError> { request, response, data, error in
            guard error == nil else { return .Failure(error!) }

783
            let JSONSerializer = Request.JSONResponseSerializer(options: .AllowFragments)
784
            let result = JSONSerializer.serializeResponse(request, response, data, error)
785 786 787 788 789 790 791

            switch result {
            case .Success(let value):
                if let response = response {
                    return .Success(T.collection(response: response, representation: value))
                } else {
                    let failureReason = "Response collection could not be serialized due to nil response"
792
                    let error = Error.errorWithCode(.JSONSerializationFailed, failureReason: failureReason)
793
                    return .Failure(error)
794
                }
795 796
            case .Failure(let error):
                return .Failure(error)
797 798 799
            }
        }

800
        return response(responseSerializer: responseSerializer, completionHandler: completionHandler)
801 802 803 804
    }
}
```

805
```swift
806
final class User: ResponseObjectSerializable, ResponseCollectionSerializable {
807 808 809
    let username: String
    let name: String

810
    init?(response: NSHTTPURLResponse, representation: AnyObject) {
811 812 813 814
        self.username = response.URL!.lastPathComponent!
        self.name = representation.valueForKeyPath("name") as! String
    }

815
    static func collection(response response: NSHTTPURLResponse, representation: AnyObject) -> [User] {
816 817 818 819 820 821 822 823 824 825 826 827 828 829 830
        var users: [User] = []

        if let representation = representation as? [[String: AnyObject]] {
            for userRepresentation in representation {
                if let user = User(response: response, representation: userRepresentation) {
                    users.append(user)
                }
            }
        }

        return users
    }
}
```

831 832
```swift
Alamofire.request(.GET, "http://example.com/users")
833 834
         .responseCollection { (response: Response<[User], NSError>) in
             debugPrint(response)
835 836 837
         }
```

M
Mattt Thompson 已提交
838 839
### URLStringConvertible

840
Types adopting the `URLStringConvertible` protocol can be used to construct URL strings, which are then used to construct URL requests. `NSString`, `NSURL`, `NSURLComponents`, and `NSURLRequest` conform to `URLStringConvertible` by default, allowing any of them to be passed as `URLString` parameters to the `request`, `upload`, and `download` methods:
M
Mattt Thompson 已提交
841

842 843 844 845 846 847 848 849 850 851 852 853 854 855 856
```swift
let string = NSString(string: "http://httpbin.org/post")
Alamofire.request(.POST, string)

let URL = NSURL(string: string)!
Alamofire.request(.POST, URL)

let URLRequest = NSURLRequest(URL: URL)
Alamofire.request(.POST, URLRequest) // overrides `HTTPMethod` of `URLRequest`

let URLComponents = NSURLComponents(URL: URL, resolvingAgainstBaseURL: true)
Alamofire.request(.POST, URLComponents)
```

Applications interacting with web applications in a significant manner are encouraged to have custom types conform to `URLStringConvertible` as a convenient way to map domain-specific models to server resources.
M
Mattt Thompson 已提交
857 858 859 860

#### Type-Safe Routing

```swift
861
extension User: URLStringConvertible {
M
Mattt Thompson 已提交
862 863 864
    static let baseURLString = "http://example.com"

    var URLString: String {
865
        return User.baseURLString + "/users/\(username)/"
M
Mattt Thompson 已提交
866 867 868 869 870
    }
}
```

```swift
871 872
let user = User(username: "mattt")
Alamofire.request(.GET, user) // http://example.com/users/mattt
M
Mattt Thompson 已提交
873 874 875 876
```

### URLRequestConvertible

877
Types adopting the `URLRequestConvertible` protocol can be used to construct URL requests. `NSURLRequest` conforms to `URLRequestConvertible` by default, allowing it to be passed into `request`, `upload`, and `download` methods directly (this is the recommended way to specify custom HTTP body for individual requests):
878 879 880 881 882 883 884

```swift
let URL = NSURL(string: "http://httpbin.org/post")!
let mutableURLRequest = NSMutableURLRequest(URL: URL)
mutableURLRequest.HTTPMethod = "POST"

let parameters = ["foo": "bar"]
885 886 887 888 889 890 891

do {
    mutableURLRequest.HTTPBody = try NSJSONSerialization.dataWithJSONObject(parameters, options: NSJSONWritingOptions())
} catch {
    // No-op
}

892 893 894 895
mutableURLRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")

Alamofire.request(mutableURLRequest)
```
M
Mattt Thompson 已提交
896

897
Applications interacting with web applications in a significant manner are encouraged to have custom types conform to `URLRequestConvertible` as a way to ensure consistency of requested endpoints. Such an approach can be used to abstract away server-side inconsistencies and provide type-safe routing, as well as manage authentication credentials and other state.
M
Mattt Thompson 已提交
898 899 900 901 902 903 904 905 906 907 908 909

#### API Parameter Abstraction

```swift
enum Router: URLRequestConvertible {
    static let baseURLString = "http://example.com"
    static let perPage = 50

    case Search(query: String, page: Int)

    // MARK: URLRequestConvertible

910 911
    var URLRequest: NSMutableURLRequest {
        let result: (path: String, parameters: [String: AnyObject]) = {
M
Mattt Thompson 已提交
912 913 914 915 916 917 918 919
            switch self {
            case .Search(let query, let page) where page > 1:
                return ("/search", ["q": query, "offset": Router.perPage * page])
            case .Search(let query, _):
                return ("/search", ["q": query])
            }
        }()

920
        let URL = NSURL(string: Router.baseURLString)!
921
        let URLRequest = NSURLRequest(URL: URL.URLByAppendingPathComponent(result.path))
M
Mattt Thompson 已提交
922 923
        let encoding = Alamofire.ParameterEncoding.URL

924
        return encoding.encode(URLRequest, parameters: result.parameters).0
M
Mattt Thompson 已提交
925 926 927 928
    }
}
```

929
```swift
930
Alamofire.request(Router.Search(query: "foo bar", page: 1)) // ?q=foo%20bar&offset=50
931 932
```

M
Mattt Thompson 已提交
933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972
#### CRUD & Authorization

```swift
enum Router: URLRequestConvertible {
    static let baseURLString = "http://example.com"
    static var OAuthToken: String?

    case CreateUser([String: AnyObject])
    case ReadUser(String)
    case UpdateUser(String, [String: AnyObject])
    case DestroyUser(String)

    var method: Alamofire.Method {
        switch self {
        case .CreateUser:
            return .POST
        case .ReadUser:
            return .GET
        case .UpdateUser:
            return .PUT
        case .DestroyUser:
            return .DELETE
        }
    }

    var path: String {
        switch self {
        case .CreateUser:
            return "/users"
        case .ReadUser(let username):
            return "/users/\(username)"
        case .UpdateUser(let username, _):
            return "/users/\(username)"
        case .DestroyUser(let username):
            return "/users/\(username)"
        }
    }

    // MARK: URLRequestConvertible

973
    var URLRequest: NSMutableURLRequest {
974
        let URL = NSURL(string: Router.baseURLString)!
A
Arnaud Mesureur 已提交
975
        let mutableURLRequest = NSMutableURLRequest(URL: URL.URLByAppendingPathComponent(path))
J
John Beynon 已提交
976
        mutableURLRequest.HTTPMethod = method.rawValue
M
Mattt Thompson 已提交
977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993

        if let token = Router.OAuthToken {
            mutableURLRequest.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization")
        }

        switch self {
        case .CreateUser(let parameters):
            return Alamofire.ParameterEncoding.JSON.encode(mutableURLRequest, parameters: parameters).0
        case .UpdateUser(_, let parameters):
            return Alamofire.ParameterEncoding.URL.encode(mutableURLRequest, parameters: parameters).0
        default:
            return mutableURLRequest
        }
    }
}
```

994 995 996 997
```swift
Alamofire.request(Router.ReadUser("mattt")) // GET /users/mattt
```

998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040
### Security

Using a secure HTTPS connection when communicating with servers and web services is an important step in securing sensitive data. By default, Alamofire will evaluate the certificate chain provided by the server using Apple's built in validation provided by the Security framework. While this guarantees the certificate chain is valid, it does not prevent man-in-the-middle (MITM) attacks or other potential vulnerabilities. In order to mitigate MITM attacks, applications dealing with sensitive customer data or financial information should use certificate or public key pinning provided by the `ServerTrustPolicy`.

#### ServerTrustPolicy

The `ServerTrustPolicy` enumeration evaluates the server trust generally provided by an `NSURLAuthenticationChallenge` when connecting to a server over a secure HTTPS connection.

```swift
let serverTrustPolicy = ServerTrustPolicy.PinCertificates(
    certificates: ServerTrustPolicy.certificatesInBundle(),
    validateCertificateChain: true,
    validateHost: true
)
```

There are many different cases of server trust evaluation giving you complete control over the validation process:

* `PerformDefaultEvaluation`: Uses the default server trust evaluation while allowing you to control whether to validate the host provided by the challenge. 
* `PinCertificates`: Uses the pinned certificates to validate the server trust. The server trust is considered valid if one of the pinned certificates match one of the server certificates.
* `PinPublicKeys`: Uses the pinned public keys to validate the server trust. The server trust is considered valid if one of the pinned public keys match one of the server certificate public keys.
* `DisableEvaluation`: Disables all evaluation which in turn will always consider any server trust as valid.
* `CustomEvaluation`: Uses the associated closure to evaluate the validity of the server trust thus giving you complete control over the validation process. Use with caution.

#### Server Trust Policy Manager

The `ServerTrustPolicyManager` is responsible for storing an internal mapping of server trust policies to a particular host. This allows Alamofire to evaluate each host against a different server trust policy. 

```swift
let serverTrustPolicies: [String: ServerTrustPolicy] = [
    "test.example.com": .PinCertificates(
        certificates: ServerTrustPolicy.certificatesInBundle(),
        validateCertificateChain: true,
        validateHost: true
    ),
    "insecure.expired-apis.com": .DisableEvaluation
]

let manager = Manager(
    serverTrustPolicyManager: ServerTrustPolicyManager(policies: serverTrustPolicies)
)
```

1041 1042
> Make sure to keep a reference to the new `Manager` instance, otherwise your requests will all get cancelled when your `manager` is deallocated.

1043 1044 1045 1046 1047 1048 1049 1050 1051
These server trust policies will result in the following behavior:

* `test.example.com` will always use certificate pinning with certificate chain and host validation enabled thus requiring the following criteria to be met to allow the TLS handshake to succeed:
  * Certificate chain MUST be valid.
  * Certificate chain MUST include one of the pinned certificates.
  * Challenge host MUST match the host in the certificate chain's leaf certificate.
* `insecure.expired-apis.com` will never evaluate the certificate chain and will always allow the TLS handshake to succeed.
* All other hosts will use the default evaluation provided by Apple.

1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067
##### Subclassing Server Trust Policy Manager

If you find yourself needing more flexible server trust policy matching behavior (i.e. wildcarded domains), then subclass the `ServerTrustPolicyManager` and override the `serverTrustPolicyForHost` method with your own custom implementation.

```swift
class CustomServerTrustPolicyManager: ServerTrustPolicyManager {
    override func serverTrustPolicyForHost(host: String) -> ServerTrustPolicy? {
        var policy: ServerTrustPolicy?

        // Implement your custom domain matching behavior...

        return policy
    }
}
```

1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081
#### Validating the Host

The `.PerformDefaultEvaluation`, `.PinCertificates` and `.PinPublicKeys` server trust policies all take a `validateHost` parameter. Setting the value to `true` will cause the server trust evaluation to verify that hostname in the certificate matches the hostname of the challenge. If they do not match, evaluation will fail. A `validateHost` value of `false` will still evaluate the full certificate chain, but will not validate the hostname of the leaf certificate.

> It is recommended that `validateHost` always be set to `true` in production environments.

#### Validating the Certificate Chain

Pinning certificates and public keys both have the option of validating the certificate chain using the `validateCertificateChain` parameter. By setting this value to `true`, the full certificate chain will be evaluated in addition to performing a byte equality check against the pinned certficates or public keys. A value of `false` will skip the certificate chain validation, but will still perform the byte equality check.

There are several cases where it may make sense to disable certificate chain validation. The most common use cases for disabling validation are self-signed and expired certificates. The evaluation would always fail in both of these cases, but the byte equality check will still ensure you are receiving the certificate you expect from the server.

> It is recommended that `validateCertificateChain` always be set to `true` in production environments.

1082 1083 1084 1085 1086 1087 1088
---

## Component Libraries

In order to keep Alamofire focused specifically on core networking implementations, additional component libraries have been created by the [Alamofire Software Foundation](https://github.com/Alamofire/Foundation) to bring additional functionality to the Alamofire ecosystem.

* [AlamofireImage](https://github.com/Alamofire/AlamofireImage) - An image library including image response serializers, `UIImage` and `UIImageView` extensions, custom image filters, an auto-purging in-memory cache and a priority-based image downloading system.
M
Mattt Thompson 已提交
1089

1090 1091 1092 1093
## Open Rdars

The following rdars have some affect on the current implementation of Alamofire.

1094 1095 1096
* [rdar://22024442](http://www.openradar.me/radar?id=6082025006039040) - Array of [SecCertificate] crashing Swift 2.0 compiler in optimized builds
* [rdar://21349340](http://www.openradar.me/radar?id=5517037090635776) - Compiler throwing warning due to toll-free bridging issue in test case
* [rdar://22307360](http://www.openradar.me/radar?id=4895563208196096) - Swift #available check not working properly with min deployment target
1097

1098 1099
    > Resolved in Xcode 7.1 beta 2. Will remove once Xcode 7.1 is out of beta.

1100 1101 1102 1103 1104 1105
## FAQ

### What's the origin of the name Alamofire?

Alamofire is named after the [Alamo Fire flower](https://aggie-horticulture.tamu.edu/wildseed/alamofire.html), a hybrid variant of the Bluebonnet, the official state flower of Texas.

1106
---
M
Mattt Thompson 已提交
1107

M
Mattt Thompson 已提交
1108
## Credits
M
Mattt Thompson 已提交
1109

1110 1111 1112 1113 1114
Alamofire is owned and maintained by the [Alamofire Software Foundation](http://alamofire.org). You can follow them on Twitter at [@AlamofireSF](https://twitter.com/AlamofireSF) for project updates and releases.

### Security Disclosure

If you believe you have identified a security vulnerability with Alamofire, you should report it as soon as possible via email to security@alamofire.org. Please do not post it to a public issue tracker.
M
Mattt Thompson 已提交
1115 1116 1117

## License

M
Mattt Thompson 已提交
1118
Alamofire is released under the MIT license. See LICENSE for details.