Skip to content

Light weight HTTP Client for Mac OS Mavericks and iOS 7 based on NSURLSession

License

Notifications You must be signed in to change notification settings

daresaydigital/BETURLSession

Repository files navigation

#BETURLSession

Build Status Version Platform

Using NSURLSession and the rest of the new iOS 7 & Mavericks foundation network classes, wrapped with syntactic sugar and convenience. No need to inherit and make a singleton. The category will keep track of your session with a session name.

##Overview

A incredibly light weight and source-readable HTTP client. Plugginable Serializers on top of builting foundation classes NSURLSession and NSURLSessionTask. Life-cycle callbacks (think before_filter or after_filter) Upload & Download progress blocks. Choose delegates and/or blocks Convenience serializers (JSON out of the box by default) to get started fast.

##Installation

pod 'BETURLSession'

##Setup

#import <BETURLSession.h>

API

Documentation for now

Sample

  NSURLSession * session = [NSURLSession bet_sessionWithName:@"Random" baseURLString:@"http://httpbin.org"];
  
  NSMutableArray * bigData = @[].mutableCopy;
  for (NSInteger i = 0; i!=50000; i++) [bigData addObject:@(i)];
  
  NSURLSessionTask * task = [session bet_taskPOSTResource:@"post" 
                                               withParams:@{@"POST" : bigData} 
                                               completion:^(BETResponse *response) {
    NSLog(@"POST completed with code %@ & error %@", 
                @(response.HTTPURLResponse.statusCode), 
                  response.error
          );
  }];
  
  BETURLSessionTaskProgressHandlerBlock (^progressHandlerWithName)(NSString *) = ^BETURLSessionTaskProgressHandlerBlock(NSString * name) {
    return ^(NSURLSessionTask *task, NSInteger bytes, NSInteger totalBytes, NSInteger totalBytesExpected) {
      NSLog(@"%@ : %@ <-> %@ <-> %@", name, @(bytes), @(totalBytes), @(totalBytesExpected));
    };
  };


  
  [task bet_setUploadProgressHandler:progressHandlerWithName(@"Upload")];
  
  [task bet_setDownloadProgressHandler:progressHandlerWithName(@"Download")];
  
  [task resume];
  

Notes

  • Proper naming
  • completion: for callbacks that are complete (option)
  • completionHandler: callbacks that are complete but need action (required)
  • handler: callbacks that need action but are not necessarily completion (required)

Contact

If you end up using BETURLSession in a project, we'd love to hear about it.

email: info@screeninteraction.com
twitter: @ScreenTwitt

License

BETURLSession is © 2013 Screen Interaction and may be freely distributed under the MIT license. See the LICENSE.md file.

About

Light weight HTTP Client for Mac OS Mavericks and iOS 7 based on NSURLSession

Resources

License

Stars

Watchers

Forks

Packages