<commit_before># HTTPRequests
__NSURLRequest extensions in Swift__

__Description__

Four different NSURLRequest extensions in Swift:

1. sum type
2. deferred result
3. deferred result and DRError
4. success and error closures

__Features__

- cURL description
- fetch data
- fetch JSON
- fetch typed JSON
- HTTP status, headers, data and NSError

__Motivation__

Demonstrates how to handle errors in an asychronous Swift API.

Initially written as the companion code for my [AppBuilders 2016](https://www.appbuilders.ch/) talk on error handling.

__Example__

```swift
    let url = NSURL(string:"http://seriot.ch/objects.json")!
    let request = NSURLRequest(URL: url)
```

1 - sum type

```swift
    request.st_fetchTypedJSON([[String:AnyObject]].self) {
        switch($0) {
        case let .Success(r, json):
            print(r.status, json)
        case let .Failure(r, nsError):
            print(r.status, nsError.localizedDescription)
        }
    }
```

2 - deferred result

```swift
    request.dr_fetchTypedJSON([[String:AnyObject]].self) {<commit_msg>added reference to 20160426_error_handling.pdf<commit_after># HTTPRequests
__NSURLRequest extensions in Swift__

__Description__

Four different NSURLRequest extensions in Swift:

1. sum type
2. deferred result
3. deferred result and DRError
4. success and error closures

__Features__

- cURL description
- fetch data
- fetch JSON
- fetch typed JSON
- HTTP status, headers, data and NSError

__Motivation__

Demonstrates how to handle errors in an asychronous Swift API.

Initially written as the companion code for my [AppBuilders 2016](https://www.appbuilders.ch/) talk on [error handling](http://seriot.ch/resources/talks_papers/20160426_error_handling.pdf).

__Example__

```swift
    let url = NSURL(string:"http://seriot.ch/objects.json")!
    let request = NSURLRequest(URL: url)
```

1 - sum type

```swift
    request.st_fetchTypedJSON([[String:AnyObject]].self) {
        switch($0) {
        case let .Success(r, json):
            print(r.status, json)
        case let .Failure(r, nsError):
            print(r.status, nsError.localizedDescription)
        }
    }
```

2 - deferred result

```swift
    request.dr_fetchTypedJSON([[String:AnyObject]].self) {
{'fraction_non_alphanumeric': 0.10133928571428572, 'fraction_numerical': 0.016964285714285713, 'mean_word_length': 3.573469387755102, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3557886', 'n_tokens_mistral': 749, 'n_tokens_neox': 690, 'n_words': 207}