Giter VIP home page Giter VIP logo

jxhttp's Introduction

JXHTTP

⚠️ ⚠️ ⚠️ JXHTTP IS NO LONGER BEING ACTIVELY MAINTAINED. We will be phasing it out of TMTumblrSDK

JXHTTP is a networking library for iOS and OS X. It leverages operation queues and GCD to provide a powerful wrapper for Cocoa's built-in NSURLConnection object, adding many useful features like block response objects and progress tracking across multiple requests. It strives to be as lightweight and readable as possible, making it easy to use or customize for advanced behavior.

To get started, simply download the latest tag and drop the JXHTTP folder into your Xcode project. There are zero external dependencies or special compiler flags, just #import "JXHTTP.h" somewhere convenient. A complete docset is included for use in Xcode or Dash, and available online at jxhttp.com. JXHTTP is also available as a CocoaPod.

JXHTTP requires iOS 5.0 or OS X 10.7 or newer.

Advantages

JXHTTPOperation offers a number of advantages over using vanilla NSURLConnection without an operation wrapper:

  • requests can be easily grouped, prioritized, cancelled, and executed concurrently
  • data can be streamed to and from disk for excellent memory efficiency
  • requests can optionally continue executing when the app is sent to the background
  • progress is easily tracked via delegate methods, response blocks, KVO, or all three
  • requests run entirely on background threads, away from the main thread and UI
  • particular attention has been paid to thread safety and is well-documented throughout

JXHTTP is production-ready and currently powers the Tumblr SDK; thousands of successful requests were performed while you read this paragraph!

Examples

See the included example project for a real-world use case in iOS.

Asynchronous

JXHTTPOperation *op = [JXHTTPOperation withURLString:@"https://encrypted.google.com/"];
op.didFinishLoadingBlock = ^(JXHTTPOperation *op) {
    NSLog(@"%@", op.responseString);
};

[[JXHTTPOperationQueue sharedQueue] addOperation:op];

Synchronous

JXHTTPOperation *op = [JXHTTPOperation withURLString:@"https://encrypted.google.com/"];
[op startAndWaitUntilFinished];

NSLog(@"%@", op.responseString);

Complex

NSURL *postURL = [NSURL URLWithString:@"https://web.site/api/POST"];
NSDictionary *postParams = @{ @"make": @"Ferrari", @"model": @"458 Italia" };

JXHTTPOperation *op = [[JXHTTPOperation alloc] initWithURL:postURL];
op.requestBody = [[JXHTTPFormEncodedBody alloc] initWithDictionary:postParams];
op.requestCachePolicy = NSURLRequestReloadIgnoringLocalAndRemoteCacheData;
op.responseDataFilePath = @"/tmp/downloaded_data";
op.trustedHosts = @[ postURL.host ];
op.performsBlocksOnMainQueue = YES;

op.didSendDataBlock = ^(JXHTTPOperation *op) {
    NSLog(@"%lld bytes uploaded so far", op.bytesUploaded);
};

[[JXHTTPOperationQueue sharedQueue] addOperation:op];

Contact

JXHTTP was created by Justin Ouellette.

Email [email protected] with questions.

jxhttp's People

Contributors

brianmichel avatar irace avatar jstn avatar kylef avatar pearapps avatar sozorogami avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.