<commit_before># SwiftClient [![Build Status](https://travis-ci.org/theadam/SwiftClient.png)](https://travis-ci.org/theadam/SwiftClient) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) [![CocoaPods](https://img.shields.io/cocoapods/v/SwiftClient.svg)](https://cocoapods.org/pods/SwiftClient)
A Simple HTTP Client written in Swift 2.

## Installation
#### Carthage
[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

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

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

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

```ogdl
github "theadam/SwiftClient" ~> 2.0.3
```

Run `carthage update` to build the framework and drag the built `SwiftClient.framework` into your Xcode project.

### CocoaPods
[CocoaPods](http://cocoapods.org) is a dependency manager for Cocoa projects. You can install it with the following command:

```bash
$ gem install cocoapods
```

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

```ruby
platform :ios, '9.0'

use_frameworks!

pod 'SwiftClient', '~> 2.0'
```

Then, run the following command:

```bash
$ pod install
```

#### Manually
1. If you are using git then add SwiftClient as a submodule using `git submodule add https://github.com/theadam/SwiftClient.git` otherwise download the project using `git clone https://github.com/theadam/SwiftClient.git` in your project folder.
2. In Xcode, Right click on the blue project icon and select "Add files to..."  Select SwiftClient/SwiftClient.xcodeproj and click Add.
3. Navigate to the target configuration window by clicking on the blue project icon, and selecting the application target under the "Targets" heading in the sidebar.
4. In the tab bar at the top of that window, open the "Build Phases" panel.
5. Expand the "Link Binary with Libraries" group, and add SwiftClient.framework.
6. In your project file `import SwiftClient` and you can start using SwiftClient.

## Usage
#### Basic Example
```swift
var client = Client()
	.baseUrl("http://myapi.org")
	.onError({e in alertError(e)});

// GET http://myapi.org/get?key=value&key2=value2
client.get("/get")
	.query("key", "value")
	.query("key2", "value2")
	.set("header", "headerValue")
	.end({(res:Response) -> Void in
		if(res.ok) { // status of 2xx
			handleResponseJson(res.body)
		}
		else {
			handleErrorJson(res.body)
		}
	})
```
## Client
A Client is like a request factory.  Client objects use functions to create Request Objects.

`client.get(url)`

`client.post(url)`

`client.put(url)`

`client.patch(url)`

`client.delete(url)`

`client.head(url)`

#### Middleware
Middleware can be used as plugins that affect every request created by a client.
```swift
Client().use({(req:Request) -> Request in
	// perform actions on the request.<commit_msg>Fix basic example<commit_after># SwiftClient [![Build Status](https://travis-ci.org/theadam/SwiftClient.png)](https://travis-ci.org/theadam/SwiftClient) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) [![CocoaPods](https://img.shields.io/cocoapods/v/SwiftClient.svg)](https://cocoapods.org/pods/SwiftClient)
A Simple HTTP Client written in Swift 2.

## Installation
#### Carthage
[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

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

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

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

```ogdl
github "theadam/SwiftClient" ~> 2.0.3
```

Run `carthage update` to build the framework and drag the built `SwiftClient.framework` into your Xcode project.

### CocoaPods
[CocoaPods](http://cocoapods.org) is a dependency manager for Cocoa projects. You can install it with the following command:

```bash
$ gem install cocoapods
```

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

```ruby
platform :ios, '9.0'

use_frameworks!

pod 'SwiftClient', '~> 2.0'
```

Then, run the following command:

```bash
$ pod install
```

#### Manually
1. If you are using git then add SwiftClient as a submodule using `git submodule add https://github.com/theadam/SwiftClient.git` otherwise download the project using `git clone https://github.com/theadam/SwiftClient.git` in your project folder.
2. In Xcode, Right click on the blue project icon and select "Add files to..."  Select SwiftClient/SwiftClient.xcodeproj and click Add.
3. Navigate to the target configuration window by clicking on the blue project icon, and selecting the application target under the "Targets" heading in the sidebar.
4. In the tab bar at the top of that window, open the "Build Phases" panel.
5. Expand the "Link Binary with Libraries" group, and add SwiftClient.framework.
6. In your project file `import SwiftClient` and you can start using SwiftClient.

## Usage
#### Basic Example
```swift
var client = Client()
	.baseUrl("http://myapi.org")
	.onError({e in alertError(e)});

// GET http://myapi.org/get?key=value&key2=value2
client.get("/get")
	.query(["key": "value", "key2": "value2"])
	.set("header", "headerValue")
	.end({(res:Response) -> Void in
		if(res.basicStatus == .OK) { // status of 2xx
			handleResponseJson(res.body)
		}
		else {
			handleErrorJson(res.body)
		}
	})
```
## Client
A Client is like a request factory.  Client objects use functions to create Request Objects.

`client.get(url)`

`client.post(url)`

`client.put(url)`

`client.patch(url)`

`client.delete(url)`

`client.head(url)`

#### Middleware
Middleware can be used as plugins that affect every request created by a client.
```swift
Client().use({(req:Request) -> Request in
	// perform actions on the request.
{'fraction_non_alphanumeric': 0.1309214795587281, 'fraction_numerical': 0.007138221933809215, 'mean_word_length': 4.761682242990654, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 18, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '155835', 'n_tokens_mistral': 2071, 'n_tokens_neox': 1922, 'n_words': 654}