Skip to content

Commit

Permalink
Updating README with new introduction and overview, and improved form…
Browse files Browse the repository at this point in the history
…atting
  • Loading branch information
mattt committed Jan 20, 2012
1 parent cc49cd8 commit 6fa7256
Showing 1 changed file with 88 additions and 43 deletions.
131 changes: 88 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,88 @@
![AFNetworking](http://engineering.gowalla.com/AFNetworking/afnetworking-logo.png "AFNetworking")
![AFNetworking](https://github.com/AFNetworking/AFNetworking/raw/gh-pages/afnetworking-logo.png "AFNetworking")

## A delightful iOS and OS X networking framework
### There's a lot to be said for a networking library that you can wrap your head around. API design matters, too. Code at its best is poetry, and should be designed to delight (but never surprise).

AFNetworking is a delightful networking library for iOS and Mac OS X. It's built on top of familiar Foundation network classes, using `NSOperation` for scheduling and concurrency, and blocks for convenience and flexibility. It's designed to make common tasks easy, and to make complex tasks simple.

## Documentation

API documentation is available at [http://afnetworking.org/Documentation](http://afnetworking.org/Documentation).

To install the API docset directly into your local Xcode organizer, first [install `appledoc`](https://github.com/tomaz/appledoc), and then clone this project and run `appledoc -p AFNetworking -c "Alamofire" --company-id com.alamofire AFNetworking/*.h`

If you're looking for something more human-friendly, or more conceptual in nature, be sure to [check out the Wiki](https://github.com/AFNetworking/AFNetworking/wiki).

## Example Projects

Be sure to download and run the example projects for iOS and Mac. Both example projects serve as models of how one might integrate AFNetworking into their own project.

## Example Usage

### JSON Request
AFNetworking is a delightful networking library for iOS and Mac OS X. It's built on top of [`NSURLConnection`](http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/Reference/Reference.html), [`NSOperation`](http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/NSOperation_class/Reference/Reference.html), and other familiar Foundation technologies. It has a modular architecture with well-designed, feature-rich APIs that are a joy to use. For example, here's how easy it is to get JSON from a URL:

``` objective-c
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://gowalla.com/users/mattt.json"]];
NSURL *url = [NSURL URLWithString:@"https://gowalla.com/users/mattt.json"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSLog(@"Name: %@ %@", [JSON valueForKeyPath:@"first_name"], [JSON valueForKeyPath:@"last_name"]);
} failure:nil];

NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease];
[queue addOperation:operation];
[operation start];
```
Perhaps the most important feature of all, however, is the amazing community of developers who use and contribute to AFNetworking every day. AFNetworking powers some of the most popular and critically-acclaimed apps on the iPhone, iPad, and Mac.
Choose AFNetworking for your next project, or migrate over your existing projects--you'll be happy you did!
## How To Get Started
- [Download AFNetworking](https://github.com/AFNetworking/AFNetworking/zipball/master) and try out the included Mac and iPhone example apps
- Read the ["Getting Started" guide](https://github.com/AFNetworking/AFNetworking/wiki/Getting-Started-with-AFNetworking), [FAQ](https://github.com/AFNetworking/AFNetworking/wiki/AFNetworking-FAQ), or [other articles in the wiki](https://github.com/AFNetworking/AFNetworking/wiki)
- Check out the [complete documentation](http://afnetworking.org/Documentation/) for a comprehensive look at the APIs available in AFNetworking
## Overview
AFNetworking is architected to be as small and modular as possible, in order to make it simple to use and extend.
<table>
<tr><th colspan="2">Core</th></tr>
<tr>
<td><a href="http://afnetworking.org/Documentation/Classes/AFURLConnectionOperation.html">AFURLConnectionOperation</a></td>
<td>An <tt>NSOperation</tt> subclass that implements the <tt>NSURLConnection</tt> delegate methods.</td>
</tr>
<tr><th colspan="2">HTTP Requests</th></tr>
<tr>
<td><a href="http://afnetworking.org/Documentation/Classes/AFHTTPRequestOperation.html">AFHTTPRequestOperation</a></td>
<td>A subclass of <tt>AFURLConnectionOperation</tt> for requests using the HTTP or HTTPS protocols. It encapsulates the concept of acceptable status codes and content types, which determine the success or failure of a request.</td>
</tr>
<tr>
<td><a href="http://afnetworking.org/Documentation/Classes/AFJSONRequestOperation.html">AFJSONRequestOperation</a></td>
<td>A subclass of <tt>AFHTTPRequestOperation</tt> for downloading and working with JSON response data.</td>
</tr>
<tr>
<td><a href="http://afnetworking.org/Documentation/Classes/AFXMLRequestOperation.html">AFXMLRequestOperation</a></td>
<td>A subclass of <tt>AFHTTPRequestOperation</tt> for downloading and working with XML response data.</td>
</tr>
<tr>
<td><a href="http://afnetworking.org/Documentation/Classes/AFPropertyListRequestOperation.html">AFPropertyListRequestOperation</a></td>
<td>A subclass of AFHTTPRequestOperation for downloading and deserializing objects with property list (plist) response data.</td>
</tr>
<tr><th colspan="2">HTTP Client</th></tr>
<tr>
<td><a href="http://afnetworking.org/Documentation/Classes/AFHTTPClient.html">AFHTTPClient</a></td>
<td>
Captures the common patterns of communicating with an web application over HTTP, including:
<ul>
<li>Making requests from relative paths of a base URL</li>
<li>Setting HTTP headers to be added automatically to requests</li>
<li>Authenticating requests with HTTP Basic credentials or an OAuth token</li>
<li>Managing an <tt>NSOperationQueue</tt> for requests made by the client</li>
<li>Generating query strings or HTTP bodies from an <tt>NSDictionary</tt></li>
<li>Constructing multipart form requests</li>
<li>Automatically parsing HTTP response data into its corresponding object representation</li>
<li>Monitoring and responding to changes in network reachability</li>
</ul>
</td>
</tr>
<tr><th colspan="2">Images</th></tr>
<tr>
<td><a href="http://afnetworking.org/Documentation/Classes/AFImageRequestOperation.html">AFImageRequestOperation</a></td>
<td>A subclass of <tt>AFHTTPRequestOperation</tt> for downloading an processing images.</td>
</tr>
<tr>
<td><a href="http://afnetworking.org/Documentation/Classes/UIImageView(AFNetworking).html">UIImageView+AFNetworking</a></td>
<td>Adds methods to the UIKit framework’s UIImageView class. The methods in this category provide support for loading remote images asynchronously from a URL.</td>
</tr>
</table>
## Example Usage
### XML Request
``` objective-c
Expand All @@ -39,9 +91,7 @@ AFXMLRequestOperation *operation = [AFXMLRequestOperation XMLParserRequestOperat
XMLParser.delegate = self;
[XMLParser parse];
} failure:nil];
NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease];
[queue addOperation:operation];
[operation start];
```

### Image Request
Expand All @@ -56,8 +106,7 @@ NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http
AFImageRequestOperation *operation = [AFImageRequestOperation imageRequestOperationWithRequest:request success:^(NSImage *image){
NSLog(@"Image loaded: %@", image);
}];
NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease];
[queue addOperation:operation];
[operation start];
```

### API Client Request
Expand All @@ -84,9 +133,7 @@ AFHTTPRequestOperation *operation = [[[AFHTTPRequestOperation alloc] initWithReq
[operation setUploadProgressBlock:^(NSInteger bytesWritten, NSInteger totalBytesWritten, NSInteger totalBytesExpectedToWrite) {
NSLog(@"Sent %d of %d bytes", totalBytesWritten, totalBytesExpectedToWrite);
}];
NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease];
[queue addOperation:operation];
[operation start];
```

### Request With HTTP Authorization Header
Expand All @@ -104,9 +151,7 @@ operation.completionBlock = ^ {
NSLog(@"[Error]: (%@ %@) %@", [operation.request HTTPMethod], [[operation.request URL] relativePath], operation.error);
}
};

NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease];
[queue addOperation:operation];
[operation start];
```
### Streaming Request
Expand All @@ -117,9 +162,7 @@ NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http
AFHTTPRequestOperation *operation = [[[AFHTTPRequestOperation alloc] initWithRequest:request] autorelease];
operation.inputStream = [NSInputStream inputStreamWithFileAtPath:[[NSBundle mainBundle] pathForResource:@"large-image" ofType:@"tiff"]];
operation.outputStream = [NSOutputStream outputStreamToMemory];
NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease];
[queue addOperation:operation];
[operation start];
```

## Requirements
Expand All @@ -134,17 +177,19 @@ AFNetworking uses [`NSJSONSerialization`](http://developer.apple.com/library/mac

### ARC Support

If you are including AFNetworking in a project that uses [Automatic Reference Counting (ARC)](http://clang.llvm.org/docs/AutomaticReferenceCounting.html) enabled, you will need to set the `-fno-objc-arc` compiler flag on all of the AFNetworking source files. To do this in Xcode, go to your active target and select the "Build Phases" tab. In the "Compiler Flags" column, set `-fno-objc-arc` for each of the AFNetworking source files.
AFNetworking will transition its codebase to ARC in a future release.

Although this is suboptimal, forking the project into an ARC and non-ARC branch would be extremely difficult to maintain. On the bright side, we're very excited about [CocoaPods](https://github.com/alloy/cocoapods) as a potential solution.
If you are including AFNetworking in a project that uses [Automatic Reference Counting (ARC)](http://clang.llvm.org/docs/AutomaticReferenceCounting.html) enabled, you will need to set the `-fno-objc-arc` compiler flag on all of the AFNetworking source files. To do this in Xcode, go to your active target and select the "Build Phases" tab. In the "Compiler Flags" column, set `-fno-objc-arc` for each of the AFNetworking source files.

## Credits

AFNetworking was created by [Scott Raymond](https://github.com/sco/) and [Mattt Thompson](https://github.com/mattt/) in the development of [Gowalla for iPhone](http://itunes.apple.com/us/app/gowalla/id304510106?mt=8).

[TTTLocationFormatter](), used in the example project, is part of [FormatterKit](https://github.com/mattt/FormatterKit), created by [Mattt Thompson](https://github.com/mattt/).
[TTTLocationFormatter](https://github.com/mattt/FormatterKit/tree/master/TTTLocationFormatter), used in the example project, is part of [FormatterKit](https://github.com/mattt/FormatterKit), created by [Mattt Thompson](https://github.com/mattt/).

AFNetworking's logo was designed by [Alan Defibaugh](http://www.alandefibaugh.com/).

AFNetworking's logo was designed by the amazingly-talented [Alan Defibaugh](http://www.alandefibaugh.com/).
And most of all, thanks to AFNetworking's [growing list of contributors](https://github.com/AFNetworking/AFNetworking/contributors).

## Contact

Expand Down

0 comments on commit 6fa7256

Please sign in to comment.