GithubHelp home page GithubHelp logo

runt18 / afjsonrpcclient Goto Github PK

View Code? Open in Web Editor NEW

This project forked from afnetworking/afjsonrpcclient

0.0 3.0 0.0 346 KB

Client for interacting with JSON-RPC APIs

License: MIT License

Ruby 3.90% Objective-C 96.10%

afjsonrpcclient's Introduction

AFJSONRPCClient

A JSON-RPC Client built on AFNetworking

JSON-RPC is a remote procedure call protocol encoded in JSON. It is a simple protocol (and very similar to XML-RPC), defining only a handful of data types and commands. JSON-RPC allows for notifications (info sent to the server that does not require a response) and for multiple calls to be sent to the server which may be answered out of order.

Example Usage

AFJSONRPCClient *client = [AFJSONRPCClient clientWithEndpointURL:[NSURL URLWithString:@"http://path.to/json-rpc/service/"]];

// Invocation
[client invokeMethod:@"method.name"
    success:^(AFHTTPRequestOperation *operation, id responseObject)
{
    // ...
}   failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    // ...
}];

// Invocation with Parameters
[client invokeMethod:@"method.name"
          parameters:@{@"foo" : @"bar", @"baz" : @(13)}
    success:^(AFHTTPRequestOperation *operation, id responseObject) {
    // ...
}   failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    // ...
}];

// Invocation with Parameters and Request ID
[client invokeMethod:@"method.name"
          parameters:@[@(YES), @(42)]
           requestId:@(2)
    success:^(AFHTTPRequestOperation *operation, id responseObject) {
    // ...
}   failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    // ...
}];

Using Protocol & NSProxy

Combine your JSON-RPC client with an Objective-C protocol for fun and profit!

@protocol ArithemeticProtocol
- (void)sum:(NSArray *)numbers
    success:(void (^)(NSNumber *sum))success;
    failure:(void (^)(NSError *error))failure;
@end

AFJSONRPCClient *client = [AFJSONRPCClient clientWithEndpointURL:[NSURL URLWithString:@"http://path.to/json-rpc/service/"]];

[[client proxyForProtocol:@protocol(ArithemeticProtocol)] sum:@[@(1), @(2)]
    success:^(NSNumber *sum) {
    // ...
}   failure:^(NSError *error) {
    // ...
}];

Subclassing

You can also subclass AFJSONRPCClient for shared class and service-related methods:

MyJSONRPCClient *client = [MyJSONRPCClient sharedClient];

[client sum:@[@(1), @(2)]
    success:^(NSNumber *sum) {
    // ...
}   failure:^(NSError *error) {
    // ...
}];

Installation

CocoaPods is the recommended way to add AFJSONRPCClient to your project.

Here's an example podfile that installs AFJSONRPCClient and its dependency, AFNetworking.

Podfile

platform :ios, '5.0'

pod 'AFJSONRPCClient', '0.1.0'

Note the specification of iOS 5.0 as the platform; leaving out the 5.0 will cause CocoaPods to fail with the following message:

[!] AFJSONRPCClient is not compatible with iOS 4.3.

License

AFJSONRPCClient and AFNetworking are available under the MIT license. See the LICENSE file for more info.

afjsonrpcclient's People

Contributors

avfonarev avatar boecko avatar dal-papa avatar mattt avatar mspasov avatar wiistriker avatar

Watchers

 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.