Giter Site home page Giter Site logo

fivesquaresoftware / jsonclient Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 164 KB

JSONClient is inspired by Ruby's REST Client. It uses simple methods based on HTTP verbs and takes URLS and dictionaries as parameters to do one thing-interact with JSON services.

License: MIT License

C 2.04% Ruby 2.43% Objective-C 95.53%

jsonclient's Introduction

About

JSONClient is a super simple, low-level library for interacting with JSON services.
JSON in the request is generated from dictionaries and JSON in the response is
parsed into dictionaries.

Including in Your Project

You can build JSONClient as a static library, or simply include the source code
in your project. If you build it as a library, include the “Headers” directory
in your project and in the header search path for your target. If you just want
to include the source, include the files in Source and Ext/JSON.

Usage

You build up request using url strings and dictionaries to represent headers and
any JSON payload.

NSString *path = [NSString stringWithFormat:"/api/devices/%“,currentDevice.udid];
JSONClient *client = [[JSONClient alloc] init];
client.username = @”user";
client.password = "password"; client.delegate = self; NSDictionary *payload = [NSDictionary dictionaryWithObject:myDictionary forKey:“device”];
NSString *urlString = [@"http://example.com" stringByAppendingPathComponent:path]

To issue a request synchonously, you use one the the simple http verb methods:

JSONResponse *r = [client post:urlString]
NSLog("body: %",r.body)

The above runs the request (an NSOperation subclass), waits for the operation to finish
and returns you the response.

You could also issue the request asynchronously on the client’s builtin operation queue:

[client queuePostRequest:urlString
payload:payload
headers:nil];

In this case, you would handle the callbacks like this:

- (void) client:(JSONClient *)client finishedQueuedRequest:(JSONRequest *)request {

logDebug("request.response: %",[request.response description]);

if([request.response isCreated]) {
// do something with a new object
} else if([request.response isOk]) {
NSLog("A-ok boss"); } else if([request.response isNotFound]) { NSLog(“We lost it”);
}
}

The callbacks come in on whatever thread the operation happened to be running in, so you are
responsible for switching to the main thread if need be.

jsonclient's People

Contributors

johnclayton avatar

Stargazers

 avatar  avatar

Watchers

 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.