Git Product home page Git Product logo

yywebworker's Introduction

YYWebWorker

Simple POST/GET ASYNC/SYNC web API retrieval helper for iOS

Simply use like this to send synchronous request:

YYWebRequestMethod method = [self isPOST] ? YYWebRequestMethodPOST : YYWebRequestMethodGET;

NSDictionary* data = @{@"username":[self username], @"password":[self password]};

NSDictionary* response;

if(method == YYWebRequestMethodPOST)
{
    response = [YYWebWorker sendPOSTSynchronousToURLString:kURL data:data];
}
else
{
    response = [YYWebWorker sendGETSynchronousToURLString:kURL data:data];
}

Or do like below if you want to do asynchronous:

YYWebRequestMethod method = [self isPOST] ? YYWebRequestMethodPOST : YYWebRequestMethodGET;

NSDictionary* data = @{@"username":[self username], @"password":[self password]};

if(method == YYWebRequestMethodPOST)
{
    [YYWebWorker sendPOSTAsynchronousToURLString:kURL data:data delegateOrNil:self];
}
else
{
    [YYWebWorker sendGETAsynchronousToURLString:kURL data:data delegateOrNil:self];
}

But in this case, dont forget to set your class as delegate of YYWebWorker. First, import and add the delegate protocol in your header file:

#import "YYWebWorkerDelegate.h"

@interface YWEViewController : UIViewController<YYWebWorkerDelegate>

And then implement the delegate method in your definition file:

- (void) webWorker:(YYWebWorker *)web didFinishReceivingAsynchronousResponseWithResult:(YYWebAsynchronousRequestResult)result error:(NSError *)error
{
    if(result == YYWebAsynchronousRequestResultOK)
    {
        // Get the response
        NSDictionary* response = [web responseDictionaryFromJSON];
    
        // Then do smething with that response
    }
}

That's it! Hope it help you in your project.. :)

p.s. Sorry at this time, it only for JSON.

yywebworker's People

Contributors

yunhasnawa avatar

Watchers

mntz 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.